Jump to content
Bixby Sayz

TPanel color

Recommended Posts

Freddy,

 

If I run this in Scar the TPanel takes on the color of the Form. Setting the panel's color only changes its border color. Running this script in Simba the color works as expected: Setting the color changes the color of the entire panel.

program New;

var
 MainForm: TForm;
 LeftPanel: TPanel;

procedure InitForm;
begin
// MainFomr := CreateForm;
 MainForm := TForm.Create(nil); // Both SCAR/Simba compatible
 with MainForm do
 begin
   ClientWidth := 500;
   ClientHeight := 500;
   Caption := 'Form Test';
   BorderStyle := bsDialog;
   Position := poScreenCenter;
 end;

 LeftPanel := TPanel.Create(MainForm);
 with LeftPanel do
 begin
   Parent := MainForm;
   ClientWidth := 150;
   Align := alLeft;
   Color := clBlack;
 end;
end;

procedure SafeInitForm;
var
 V: TVariantArray;
begin
 SetArrayLength(V, 0);
 ThreadSafeCall('InitForm', V);
end;

procedure ShowFormModal;
begin
 MainForm.ShowModal;
end;

procedure SafeShowFormModal;
var
 V: TVariantArray;
begin
 SetArrayLength(V, 0);
 ThreadSafeCall('ShowFormModal', V);
end;

begin
 SafeInitForm;
 SafeShowFormModal;
end.

Link to comment
Share on other sites

You need to set the panel's "ParentBackground" property to False:

 

program New;

var
 MainForm: TForm;
 LeftPanel: TPanel;

procedure InitForm;
begin
// MainFomr := CreateForm;
 MainForm := TForm.Create(nil); // Both SCAR/Simba compatible
 with MainForm do
 begin
   ClientWidth := 500;
   ClientHeight := 500;
   Caption := 'Form Test';
   BorderStyle := bsDialog;
   Position := poScreenCenter;
 end;

 LeftPanel := TPanel.Create(MainForm);
 with LeftPanel do
 begin
   Parent := MainForm;
   ClientWidth := 150;
   Align := alLeft;
   Color := clBlack;
   ParentBackground := False;
 end;
end;

procedure SafeInitForm;
var
 V: TVariantArray;
begin
 SetArrayLength(V, 0);
 ThreadSafeCall('InitForm', V);
end;

procedure ShowFormModal;
begin
 MainForm.ShowModal;
end;

procedure SafeShowFormModal;
var
 V: TVariantArray;
begin
 SetArrayLength(V, 0);
 ThreadSafeCall('ShowFormModal', V);
end;

begin
 SafeInitForm;
 SafeShowFormModal;
end.

 

However, you should make sure you use CreateForm for SCAR unless you plan on freeing the form yourself, because else you'll create a huge memoryleak.

Link to comment
Share on other sites

You need to set the panel's "ParentBackground" property to False:
Ah Ha! Knew I was missing something simple.

 

However, you should make sure you use CreateForm for SCAR unless you plan on freeing the form yourself, because else you'll create a huge memoryleak.
Yeah, I generally do. Changed it that one time just so I could compile & run in Simba to see how it behaved there.
Link to comment
Share on other sites

You should consider using SCAR's form designer for this, it lets you visually design the forum, which usually prevents this kind of problems, as in this case for example ParentBackground would be set to False automatically when you change the panel's color and it will also output a very clean script/include file for you to use :)

Edited by Freddy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...