Since some people have been asking about this i made a tutorial. I am pretty sure this only works in Scar 3.10-3.11. For this tutorial I am assuming you have standard knowledge of how a form works.
First start out with a simple form
SCAR Code:
program New;
var
// InitForm variables.
frmDesign : TForm;
Button1 : TButton;
colors : TEdit;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Position := poDesktopCenter;
frmDesign.BorderStyle := bsSingle;
frmDesign.Width := 300;
frmDesign.Height := 173;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.PixelsPerInch := 96;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.Left := 20;
Button1.Top := 70;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Pick color';
Button1.TabOrder := 8;
colors := TEdit.Create(frmDesign);
colors.Parent := frmDesign;
colors.Left := 100;
colors.Top := 73;
colors.Width := 121;
colors.Height := 21;
colors.TabOrder := 9;
colors.Text := 'color';
end;
procedure SafeInitForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitForm', V);
end;
procedure ShowInitFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowInitFormModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowInitFormModal', V);
end;
procedure MainInitForm;
begin
try
SafeInitForm;
SafeShowInitFormModal;
finally
FreeForm(frmDesign);
except
WriteLn('An error seems to have occurred in: InitForm');
end;
end;
begin
ClearDebug;
MainInitForm;
end.
Then we add a Tcolorpicker var at the top, and create the tcolorpicker in the initform procedure.
SCAR Code:
program New;
var
// InitForm variables.
frmDesign : TForm;
Button1 : TButton;
colors : TEdit;
colorpicker : TColorPicker;//Add this
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Position := poDesktopCenter;
frmDesign.BorderStyle := bsSingle;
frmDesign.Width := 300;
frmDesign.Height := 173;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.PixelsPerInch := 96;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.Left := 20;
Button1.Top := 70;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Pick color';
Button1.TabOrder := 8;
colors := TEdit.Create(frmDesign);
colors.Parent := frmDesign;
colors.Left := 100;
colors.Top := 73;
colors.Width := 121;
colors.Height := 21;
colors.TabOrder := 9;
colors.Text := 'color';
colorpicker := Tcolorpicker.Create(frmdesign);//add this too
end;
procedure SafeInitForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitForm', V);
end;
procedure ShowInitFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowInitFormModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowInitFormModal', V);
end;
procedure MainInitForm;
begin
try
SafeInitForm;
SafeShowInitFormModal;
finally
FreeForm(frmDesign);
except
WriteLn('An error seems to have occurred in: InitForm');
end;
end;
begin
ClearDebug;
MainInitForm;
end.
then we have to make two procedures to make the tcolorpicker do something so first under the Tbutton put this and add this procedure.
SCAR Code:
program New;
var
// InitForm variables.
frmDesign : TForm;
Button1 : TButton;
colors : TEdit;
colorpicker : TColorPicker;
//add this procedure
Procedure colorpick(sender: Tobject);
begin
colorpicker.Pick;
colorpicker.onpick := @colorpicked;
end;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Position := poDesktopCenter;
frmDesign.BorderStyle := bsSingle;
frmDesign.Width := 300;
frmDesign.Height := 173;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.PixelsPerInch := 96;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.Left := 20;
Button1.Top := 70;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Pick color';
Button1.TabOrder := 8;
Button1.Onclick := @colorpick;// add this
colors := TEdit.Create(frmDesign);
colors.Parent := frmDesign;
colors.Left := 100;
colors.Top := 73;
colors.Width := 121;
colors.Height := 21;
colors.TabOrder := 9;
colors.Text := 'color';
colorpicker := Tcolorpicker.Create(frmdesign);
end;
procedure SafeInitForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitForm', V);
end;
procedure ShowInitFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowInitFormModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowInitFormModal', V);
end;
procedure MainInitForm;
begin
try
SafeInitForm;
SafeShowInitFormModal;
finally
FreeForm(frmDesign);
except
WriteLn('An error seems to have occurred in: InitForm');
end;
end;
begin
ClearDebug;
MainInitForm;
end.
this makes it so when you click the button it goes to the colorpicker and when it picks it goes to this next procedure. so add this one last procedure and you are done.
SCAR Code:
program New;
var
// InitForm variables.
frmDesign : TForm;
Button1 : TButton;
colors : TEdit;
colorpicker : Tcolorpicker;
//add this
Procedure colorpicked(Sender: TObject; Color, X, Y: Integer);
begin
colors.text:= inttostr(color);
end;
Procedure colorpick(sender: Tobject);
begin
colorpicker.Pick;
colorpicker.onpick := @colorpicked;
end;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Position := poDesktopCenter;
frmDesign.BorderStyle := bsSingle;
frmDesign.Width := 300;
frmDesign.Height := 173;
frmDesign.Caption := 'frmDesign';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.PixelsPerInch := 96;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.Left := 20;
Button1.Top := 70;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Pick color';
Button1.TabOrder := 8;
Button1.Onclick := @colorpick;
colors := TEdit.Create(frmDesign);
colors.Parent := frmDesign;
colors.Left := 100;
colors.Top := 73;
colors.Width := 121;
colors.Height := 21;
colors.TabOrder := 9;
colors.Text := 'color';
colorpicker := Tcolorpicker.Create(frmdesign);
end;
procedure SafeInitForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitForm', V);
end;
procedure ShowInitFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowInitFormModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowInitFormModal', V);
end;
procedure MainInitForm;
begin
try
SafeInitForm;
SafeShowInitFormModal;
finally
FreeForm(frmDesign);
except
WriteLn('An error seems to have occurred in: InitForm');
end;
end;
begin
ClearDebug;
MainInitForm;
end.
that just makes it so when it picks the color it takes the color and puts it in the color.text variable.
and your done now have fun.