PDA

View Full Version : TScrollBox Form Component In Scar by Ron



Ron
02-04-2007, 11:18 PM
TScrollBox Form Component In Scar
by Ron

Another hidden component within scar. The TScrollBox will let you scroll information in a small form which is useful if the information you're scrolling is too wide or tall to fit. Here is a picture of the form you will be creating!

Screenshot:
http://img245.imageshack.us/img245/7108/tscrollboxtutorialbyronhz9.png

1. Start out with a regular form like this one:


{ Program created by Ron to explain the TScrollBox component. }

program TScrollBoxTutorialByRon;

var
// InitForm variables.
frmDesign : TForm;

procedure InitForm;
begin
// Create frmDesign - Main Form.
frmDesign := CreateForm;
frmDesign.Position := poDesktopCenter; // Centers the form to middle of screen.
frmDesign.Caption := 'Testing TScrollBox - Tutorial by Ron'; // Form title.
frmDesign.Width := 350;
frmDesign.Height := 300;
frmDesign.BorderStyle := bsSingle; // Makes form not resizable.
frmDesign.BorderIcons := [biMinimize,biSystemMenu]; // Disables maximize.
end;

// Safe call to the InitForm procedure.
procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(v, 0);
ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;

// Safe call to the ShowFormModal procedure.
procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(v, 0);
ThreadSafeCall('ShowFormModal', v);
end;

// Call all the safe procedures and then free the form from memory.
procedure MainInitForm;
begin
SafeInitForm;
SafeShowFormModal;
FreeForm(frmDesign);
end;

begin
ClearDebug;
MainInitForm;
end.


2. Now to add a TScrollBox and something to put in the box.

Under the variables, insert this code. This will declare a ScrollBox, 5 CheckBoxes, and a Label.


ScrollBox1 : TScrollBox;
CheckBox1,CheckBox2,CheckBox3,CheckBox4,CheckBox5 : TCheckBox;
Label1 : TLabel;


3. In the InitForm under the frmDesign code, place this code in to setup the ScrollBox1.
This creates the TScrollBox, sets it to the main form, and sets its width/height.


// Create ScrollBox1.
ScrollBox1 := TScrollBox.Create(frmDesign);
ScrollBox1.Parent := frmDesign;
ScrollBox1.Height := 150;
ScrollBox1.Width := 300;
ScrollBox1.BorderStyle := bsNone; // Gets rid of ugly border.
ScrollBox1.Color := 14258279; // Changes color.


4. Now you're ready to put something in the ScrollBox1.

Let's add the components we declared before and let's put them INSIDE the ScrollBox1. Woo, feeling crazy today. To put anything inside the ScrollBox1, just set whatever components you have as parents to it. Example, normally you would do something like Label1.Parent := frmDesign. Instead, do Label1.Parent := ScrollBox1. Simple as that!

Put this code right under the ScrollBox1 code.


// Create Label1.
Label1 := TLabel.Create(frmDesign);
Label1.Parent := ScrollBox1; // Place ScrollBox1 as the parent
Label1.Top := 20;
Label1.Left := 20;
Label1.Caption := 'Testing ScrollBox1!';
Label1.Font.Style := [fsBold]; // Bolds the text.
// Create CheckBox1.
CheckBox1 := TCheckBox.Create(frmDesign);
CheckBox1.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox1.Top := 40;
CheckBox1.Left := 20;
CheckBox1.Caption := 'Do you find this component useful?';
CheckBox1.Width := 200;
// Create CheckBox2.
CheckBox2 := TCheckBox.Create(frmDesign);
CheckBox2.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox2.Top := 80;
CheckBox2.Left := 20;
CheckBox2.Caption := 'Will you be putting this in your future programs?';
CheckBox2.Width := 250;
// Create CheckBox3.
CheckBox3 := TCheckBox.Create(frmDesign);
CheckBox3.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox3.Top := 120;
CheckBox3.Left := 20;
CheckBox3.Caption := 'Did you know you can change the background color' +
' of your scrollbox?';
CheckBox3.Width := 360;
// Create CheckBox4.
CheckBox4 := TCheckBox.Create(frmDesign);
CheckBox4.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox4.Top := 160;
CheckBox4.Left := 20;
CheckBox4.Caption := 'Did you like this tutorial?';
CheckBox4.Width := 200;
// Create CheckBox5.
CheckBox5 := TCheckBox.Create(frmDesign);
CheckBox5.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox5.Top := 200;
CheckBox5.Left := 20;
CheckBox5.Caption := 'Was this tutorial informative enough?';
CheckBox5.Width := 200;


5. Your code should now look exactly like this:


{ Program created by Ron to explain the TScrollBox component. }

program TScrollBoxTutorialByRon;

var
// InitForm variables.
frmDesign : TForm;
ScrollBox1 : TScrollBox;
CheckBox1,CheckBox2,CheckBox3,CheckBox4,CheckBox5 : TCheckBox;
Label1 : TLabel;

procedure InitForm;
begin
// Create frmDesign - Main Form.
frmDesign := CreateForm;
frmDesign.Position := poDesktopCenter; // Centers the form to middle of screen.
frmDesign.Caption := 'Testing TScrollBox - Tutorial by Ron'; // Form title.
frmDesign.Width := 350;
frmDesign.Height := 300;
frmDesign.BorderStyle := bsSingle; // Makes form not resizable.
frmDesign.BorderIcons := [biMinimize,biSystemMenu]; // Disables maximize.
// Create ScrollBox1.
ScrollBox1 := TScrollBox.Create(frmDesign);
ScrollBox1.Parent := frmDesign;
ScrollBox1.Height := 150;
ScrollBox1.Width := 300;
ScrollBox1.BorderStyle := bsNone; // Gets rid of ugly border.
ScrollBox1.Color := 14258279; // Changes color.
// Create Label1.
Label1 := TLabel.Create(frmDesign);
Label1.Parent := ScrollBox1; // Place ScrollBox1 as the parent
Label1.Top := 20;
Label1.Left := 20;
Label1.Caption := 'Testing ScrollBox1!';
Label1.Font.Style := [fsBold]; // Bolds the text.
// Create CheckBox1.
CheckBox1 := TCheckBox.Create(frmDesign);
CheckBox1.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox1.Top := 40;
CheckBox1.Left := 20;
CheckBox1.Caption := 'Do you find this component useful?';
CheckBox1.Width := 200;
// Create CheckBox2.
CheckBox2 := TCheckBox.Create(frmDesign);
CheckBox2.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox2.Top := 80;
CheckBox2.Left := 20;
CheckBox2.Caption := 'Will you be putting this in your future programs?';
CheckBox2.Width := 250;
// Create CheckBox3.
CheckBox3 := TCheckBox.Create(frmDesign);
CheckBox3.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox3.Top := 120;
CheckBox3.Left := 20;
CheckBox3.Caption := 'Did you know you can change the background color' +
' of your scrollbox?';
CheckBox3.Width := 360;
// Create CheckBox4.
CheckBox4 := TCheckBox.Create(frmDesign);
CheckBox4.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox4.Top := 160;
CheckBox4.Left := 20;
CheckBox4.Caption := 'Did you like this tutorial?';
CheckBox4.Width := 200;
// Create CheckBox5.
CheckBox5 := TCheckBox.Create(frmDesign);
CheckBox5.Parent := ScrollBox1; // Place ScrollBox1 as the parent.
CheckBox5.Top := 200;
CheckBox5.Left := 20;
CheckBox5.Caption := 'Was this tutorial informative enough?';
CheckBox5.Width := 200;
end;

// Safe call to the InitForm procedure.
procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(v, 0);
ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;

// Safe call to the ShowFormModal procedure.
procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(v, 0);
ThreadSafeCall('ShowFormModal', v);
end;

// Call all the safe procedures and then free the form from memory.
procedure MainInitForm;
begin
SafeInitForm;
SafeShowFormModal;
FreeForm(frmDesign);
end;

begin
ClearDebug;
MainInitForm;
end.


6. Explaining some of its properties.

BorderStyle - To set a borderstyle for it. Ex: bsNone, bsSingle, etc.
Color - To set the background color. Ex: 255 will make the background red.
CTL3D - If false, it won't look cool 3D like.
Cursor - To change the cursor when the mouse is over it. Ex. crHandPoint
Font - To change to the font, font-color, font-style, font-size, etc.
HorzScrollBar - To set its increment, position, scrollpos, and to set its visibility.
VertScrollBar - Same as HorzScrollBar except that it's vertical. :P

More common properties also exist such as visible,top,left,width,height,taborder,tabstop,hin t,showhint, etc.

~Ron :)

Freddy1990
02-04-2007, 11:25 PM
Hmm, scrollbox is very nice and all, but why would you want to use it if you can just use the entire form?

Ron
02-04-2007, 11:35 PM
Say you wanted to make some app to do something, with like 50 options. Each one very useful, and there are so many that you need to adjust your resolution to like... 2048 x 2048 or something (Exagerating...). Any way, to make it much easier on yourself and everyone using your script, it would help loads by just making a TScrollBox. :)

This is what I wanted cause my DFM parser thing is starting to get more and more options, that I wanted to add something like this. It's perfect for that if anyone wants a real app example.

:)

Bam Bam
02-04-2007, 11:37 PM
Yeah I cant see where this would be extremely useful or look good.

Freddy1990
02-05-2007, 10:33 PM
This is what I wanted cause my DFM parser thing is starting to get more and more options, that I wanted to add something like this.

Can't you just wait for divi and use tabs? lol :)