TLabel does not show in ScaleRichViewEdit

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
nielisheng
Posts: 4
Joined: Sat Jan 09, 2016 2:56 am

TLabel does not show in ScaleRichViewEdit

Post 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;
nielisheng
Posts: 4
Joined: Sat Jan 09, 2016 2:56 am

I use TPanel instead, It works fine.

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
nielisheng
Posts: 4
Joined: Sat Jan 09, 2016 2:56 am

TSRVLabel works perfect

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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);
Post Reply