Page 1 of 1

TLabel does not show in ScaleRichViewEdit

Posted: Sat Jan 09, 2016 9:40 am
by nielisheng
I think it might be a label's caption font color problem. for you can select it, but label's caption looks blank.


procedure TForm1.SRVButton1Click(Sender: TObject);
var
ACtrl: TLabel;
sItemNo: string;
sName: TRVAnsiString;
aAlign: TRVVAlign;
item: TCustomRVItemInfo;
begin
item := SRichViewEdit1.ActiveEditor.GetCurrentItem;
if item = nil then exit;
ACtrl := TLabel.Create(SRichViewEdit1.ActiveEditor);
ACtrl.Name := 'Lbl1';
ACtrl.Caption := 'Label1';
SRichViewEdit1.ActiveEditor.InsertControl(ACtrl.Name, ACtrl, rvvaBaseline);
SRichViewEdit1.Reformat;
end;

I use TPanel instead, It works fine.

Posted: Sun Jan 10, 2016 2:39 am
by nielisheng
Sorry, TLabel can be replaced by TPanel, I have changed our code

procedure TFInsertControls.ToolButton13Click(Sender: TObject);
var
c: TPanel;
begin
c := TPanel.Create(nil);
c.Parent := SRichViewEdit1.ActiveEditor;
c.Name := 'Panel';
c.Caption := 'Panel';
c.Font.Name := 'Microsoft Sans Serif';
c.Color := clWhite;
c.BevelInner := bvNone;
c.BevelOuter := bvNone;
c.BorderWidth := 0;
c.BorderStyle := bsNone;
c.Ctl3D := False;
SRichViewEdit1.ActiveEditor.InsertControl('teste', c, rvvaMiddle);
end;

Posted: Sun Jan 10, 2016 9:47 am
by Sergey Tkachenko
Yes, TLabel was not supported in ScaleRichView, only controls inherited from TWinControl.
We made some changes to support TLabel (will be in the next update), however, there are much better alternatives:
1) TRVLabelItemInfo - not a control, it's a document item displaying text.
2) TSRVLabel - a label included in SRVControls.

These options display and scale text with higher quality than TLabel when inserted in TSRichViewEdit.

TSRVLabel works perfect

Posted: Mon Jan 11, 2016 1:57 pm
by nielisheng
Thank you

procedure TFrameNRV.InsertLabel(rves: TCustomRichViewEdit;
sName_Prefix, sCaption: string);
var
ACtrl: TSRVLabel;
sItemNo: string;
sName: TRVAnsiString;
aAlign: TRVVAlign;
ATag: Integer;
item: TCustomRVItemInfo;
begin
ACtrl := TSRVLabel.Create(rves);
ACtrl.Parent := rves;
ACtrl.Name := 'SRVLabel1';
ACtrl.Anchors := [akLeft, akBottom];
ACtrl.Caption := sCaption;
ACtrl.AutoSize := True;
ACtrl.BackgroundColor := clWhite;
ACtrl.ForegroundColor := clBlack;
rves.InsertControl(ACtrl.Name, ACtrl, rvvaBaseline);
if rves.CurItemStyle = rvsComponent then
rves.SetCurrentItemExtraIntProperty(rvepResizable, 1, True);

rves.Reformat;
rves.SelectControl(ACtrl);
end;

Posted: Mon Jan 11, 2016 2:26 pm
by Sergey Tkachenko
You can omit Reformat, editing methods reformat the changed fragment themselves.

Also, InsertControl is a function, you can call:

Code: Select all

if rves.InsertControl(ACtrl.Name, ACtrl, rvvaBaseline) then
  rves.SetCurrentItemExtraIntProperty(rvepResizable, 1, True); 
Also, it's recommended to group undo for insertion and changing properties:

Code: Select all

rves.TopLevelEditor.BeginUndoGroup(rvutInsert);
rves.TopLevelEditor.SetUndoGroupMode(True);
if rves.InsertControl(ACtrl.Name, ACtrl, rvvaBaseline) then
begin
  rves.SetCurrentItemExtraIntProperty(rvepResizable, 1, True);
  rves.TopLevelEditor.SelectControl(ACtrl); 
end;
rves.TopLevelEditor.SetUndoGroupMode(False);