I want to change the colour of the font on tab to red if there are any notes existing for the record.
tshNotes.Caption.Color:= clWindow;
Returns error
[dcc32 Error] fMaintenanceU.pas(711): E2018 Record, object or class type required
I want to change the colour of the font on tab to red if there are any notes existing for the record.
tshNotes.Caption.Color:= clWindow;
Returns error
[dcc32 Error] fMaintenanceU.pas(711): E2018 Record, object or class type required
I am not sure why you are getting the error, but you cant change the tab colours like that. I have every component subclassed so I can do these things. Heres the event code that colours the tab and draws an image. Its hooked to OnDrawTab event. I am actually colouring the Active Tab, but you can adapt it.
procedure TRGTabCtrl.DoOnDrawTab ( Control : TCustomTabControl;
TabIndex: Integer;
const Rect : TRect;
Active : Boolean);
var
R : TRect;
B : string;
O : integer;
begin
{ Get Rectangle }
R := TabRect(TabIndex);
{ Handle Tab Color }
if FActiveTabColor <> DefTabColor
then begin
if Active
then Canvas.Brush.Color := FActiveTabColor
else Canvas.Brush.Color := FTabColor;
Canvas.FillRect (R);
end;
{ Draw the Image }
if not (csDesigning in ComponentState)
then
if (TabIndex >= 0) and Assigned (Images) and (TabIndex < Images.Count)
then begin
if not Assigned (FBitmap)
then FBitmap := TBitMap.Create;
if Images.GetBitmap (TabIndex,FBitmap)
then begin
O := (R.Bottom - R.Top - FBitmap.Height) div 2;
if O < 1
then O := 1;
Canvas.BrushCopy(Bounds(R.Left+2, R.Top+O, FBitmap.Width, FBitmap.Height),
FBitmap,
Bounds(0, 0, FBitmap.Width, FBitmap.Height),
clwhite
{FBitmap.TransparentColor does not work});
R.Left := R.Left + FBitmap.Width +2;
end;
end;
{ Draw the Tab Text, note Pages has Physical Pages, Tabs has
visible pages, so dont use Pages to get the Caption }
B := Tabs [TabIndex];
Canvas.Font := Self.Font;
if Active
then Canvas.Font.Style := Canvas.Font.Style + [fsBold];
Canvas.Pen.Color := Canvas.Font.Color;
DrawText (Canvas.Handle,pchar(B),length(B),R,DT_CENTER or DT_VCENTER or DT_SINGLELINE);
{ Call Linked Event }
if Assigned (FOldDrawEvent)
then FOldDrawEvent (Control, TabIndex, Rect, Active);
end;
Great thanks.