Jump to content
Devis

Some questions on scroll bars and CheckBoxes?

Recommended Posts

Could someone link me to a tutorial or explain to me how to make a vertical scroll bar on a form? Ive seen the tutorial made by Freddy which shows how to make a horizontal scroll bar here: http://villavu.com/forum/showthread.php?t=3709 Also I dont understand how you make the scroll bar actually move the page?

 

Another question I wanted to ask was how do I make TCheckboxes and a selection box (Dont know what they are acctualy called)?

Heres what I mean: Boxes.png

 

 

Thanks

Devis

Link to comment
Share on other sites

Could someone link me to a tutorial or explain to me how to make a vertical scroll bar on a form? Ive seen the tutorial made by Freddy which shows how to make a horizontal scroll bar here: http://villavu.com/forum/showthread.php?t=3709 Also I dont understand how you make the scroll bar actually move the page?

 

Another question I wanted to ask was how do I make TCheckboxes and a selection box (Dont know what they are acctualy called)?

Heres what I mean: [ATTACH=CONFIG]505[/ATTACH]

 

 

Thanks

Devis

 

I learned most of these things through a book (Not delphi). You have to realize that tons of programming languages use sort of the same thing when it comes to Forms. Like I learned from a Visual Basic 6 book. VB.net's form making isn't much different from that either, and neither is Delphi's and Scar's. If I remember correctly, the TScrollBar has values for everything, and has the ability to scroll certain things or w/e. TCheckBox, and TRadioButton are very simplistic. You just create one, you can give it text (somehow i forget). Like for checkbox there is a property like TCheckBox.Checked. You just create them then place them like many other form components.

 

As far as learning forms goes. http://www.homeandlearn.co.uk/net/vbNet.html

Well I learned a lot from VB6 for dummies. You'd have to scramble for some good resources for free learning or pay like 5-10$ for the VB6 for dummies book.

 

[sCAR]

var

Check: TCheckBox;

Radio: TRadioButton;

 

Check := TCheckBox.Create(Form);

Radio := TRadioButton.Create(Form);

[/sCAR]

 

In SCAR Divi, just type like TCheck then Hit Ctrl + Space and you will see the TCheckBox thingy. Then put a dot after it like TCheckBox. then hit Ctrl + Space to see the components stuff.

Edited by LordJashin
Link to comment
Share on other sites

Right Ive managed to sort out my TCheckBoxes and TRadioButtons so they work fine. But Im still smashing my head against a wall to get this dam scroll bar thing to work...

 

Ive been trawling through loads of delphi,visual basic and scar code and Ive come up with this thing... I don't think its very good, and I don't think its the correct way to make what I'm trying to do but I cant figure it out. From what Ive been reading I think I need to make a TPanel and make that the part that scrolls??

 

Any way this is the code I have been using:

 

program New;


var
 frmDesign: TForm;
 Label1, Label2, Label3, Label4: TLabel;
 sb: TScrollBar;
 MyScrollBox: TScrollBox;

 Background: TImage;
 b, w, h: Integer;


procedure OnScroll(sender: TObject);
begin
 MyScrollBox.Top := (-sb.Position) + 50
end;  

procedure InitForm;
begin
 frmDesign := CreateForm;          // This will create your form. MUST be called first.
 frmDesign.Left := 100;            // How many pixels from the left must the form be vissible?
 frmDesign.Top := 100;             // How many pixels from the top must the form be vissible?
 frmDesign.Width := 800;           // The width of you form in pixels
 frmDesign.Height := 500;          // The height of you form in pixels
 frmDesign.Caption := 'Test!';     // The name of your form? This will be shown in the upper left balk
 frmDesign.Color := ClWhite;       // The background color of your form ("ClWhite", "ClBlack" ect, or just an color like: 123456)
 frmDesign.Font.Color := ClBlack;        // The color of the text (Tlabels) when you have those
 frmDesign.Font.Name := 'Comic Sans MS'; // The name of the font you want the Tlabels to be 

 MyScrollBox := TScrollBox.Create(frmDesign);
 MyScrollBox.Parent := frmDesign;
 MyScrollBox.Color := 14145495;
 MyScrollBox.Left := 50;
 MyScrollBox.Top := 50;
 MyScrollBox.Width := 400;
 MyScrollBox.Height := 600;

 Background := TImage.Create(frmDesign);
 Background.Parent := frmDesign;
 Background.BringToFront;
 Background.Left := 1;
 Background.Top := 1;
 Background.Width := 800;
 Background.Height := 500;
 b := loadbitmap('{C:\ProgramFiles\ BLAH BLAH ..Where you save the background pic}\Background1.bmp');
 getbitmapsize(b, w, h);
 copycanvas(getbitmapcanvas(b), Background.canvas, 0, 0, w, h, 0, 0, w, h);

 Label1 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label1.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label1.Top := 20;                       // how many pixels from the left
 Label1.Left := 20;                      // how many pixels from the top
 Label1.Caption := 'Item Number : 1';  // What does your label need to say?
 Label1.Font.Size := 17;                 // The size of your text
 Label1.Font.Color := ClRed;             // The color of your text
 Label1.Font.Name := 'Comic Sans MS';    // The font name of your text 

 Label2 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label2.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label2.Top := 60;                       // how many pixels from the left
 Label2.Left := 20;                      // how many pixels from the top
 Label2.Caption := 'Item Number : 2';  // What does your label need to say?
 Label2.Font.Size := 17;                 // The size of your text
 Label2.Font.Color := ClRed;             // The color of your text
 Label2.Font.Name := 'Comic Sans MS';    // The font name of your text

 Label3 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label3.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label3.Top := 100;                       // how many pixels from the left
 Label3.Left := 20;                      // how many pixels from the top
 Label3.Caption := 'Item Number : 3';  // What does your label need to say?
 Label3.Font.Size := 17;                 // The size of your text
 Label3.Font.Color := ClRed;             // The color of your text
 Label3.Font.Name := 'Comic Sans MS';    // The font name of your text

 Label4 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label4.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label4.Top := 140;                       // how many pixels from the left
 Label4.Left := 20;                      // how many pixels from the top
 Label4.Caption := 'Item Number : 4';  // What does your label need to say?
 Label4.Font.Size := 17;                 // The size of your text
 Label4.Font.Color := ClRed;             // The color of your text
 Label4.Font.Name := 'Comic Sans MS';    // The font name of your text


 sb := TScrollBar.Create(frmDesign);
 sb.Parent := frmDesign;
 sb.Kind := sbVertical;
 sb.Left := 455;
 sb.Top := 50;
 sb.Width := 20;
 sb.Height := 300;
 //sb.Align := alRight;
 sb.Min := 0;
 sb.Max := 200; //Change Max height to scroll further!
 sb.Position := 0;
 sb.OnChange := @OnScroll;

end;

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

procedure ShowFormModal;
begin
 frmDesign.ShowModal;
end;

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

begin
 SafeInitForm;        
 SafeShowFormModal;  
end.

 

This is the background image I was using and trying to make the scrollbox go behind..

Background1.bmp

 

Can any one help with this? Thanks

Link to comment
Share on other sites

This link will help you out. So yeah go through that. To sum it up, basically TScrollbars have a min, max, increment, and all sorts of variables. One you can set so that it starts scrolling at a certain length. Anyway doing this on SCAR Divi you could use Tools->Form Editor. I suggest you use Delphi though. Also that page says that you can scroll the form, make like tons of things scrollable.

 

I could get you Delphi, then teach you so you could make a form there then port it over to SCAR Divi. Just hit me up on Skype. Remember that some SCAR Divi form components may be broken/missing stuff.

 

So what are you trying to accomplish, the scrolling thing inside the scrollbox or what. Using Events was smart way to start out, but there's probably ways you can do without.

Edited by LordJashin
Link to comment
Share on other sites

What im basically trying to do is create a section on my form that has a vertical scroll bar at the side, and when you scroll down the section scrolls down. Like a list of things that are in a certain section (Box) but I dont want to use TListBox because I want more than just a list of texts, I want other things in the scrollable section like TEdit boxes, TRadioButtons, and some TLabels and to be able to scroll down the area. Thats all im trying to create lol

 

I have used the TForm Editor before but once I saved my form in the editor I could never understand how to get it to work in script form, like when you go to Open->then your saved form, it opens up in a strange format. (If you know what I mean)

 

I will probs drop you a message on skype if i cant get it to work soon if you dont mind.

Edited by Devis
Link to comment
Share on other sites

That weird format is how Delphi views DFM files. (Its own way of storing forms). SCAR is made with Delphi, so its Form editor does that too. Basically the weird format is the Form as a Class object (a variable of a class). In delphi, you can edit your forms, and add new Form controls. It will not add to your code that you are viewing/using that has your form class, it will just add to that DFM file, and have it linked in when you compile. Its good to separate code.

 

I believe it is something like:

[sCAR]

with object do

Size := 3;

// etc

[/sCAR]

 

I would use a transparent panel/frame then put controls inside of it. I'm pretty sure you can make it scroll. Never tried though. I'll experiment later if I have time, hit me up on skype whenever.

Link to comment
Share on other sites

FINALLY!! Ive worked out what I was trying to do! I read your suggestion on looking at the TForm editor again, and just realized there's a little tab at the bottom that lets you view the script for the form, and export to SCAR. So i basically looked through that and took out the parts of code that I needed using a TScrollbox. And it works perfectly now!

 

Here is the finished code I got working, and its 10 times more simple that what I was trying to do before:

 

program New;


var
 frmDesign: TForm;
 Label1, Label2, Label3, Label4: TLabel;

 MyScrollBox: TScrollBox;


procedure InitForm;
begin
 frmDesign := CreateForm;          // This will create your form. MUST be called first.
 frmDesign.Left := 100;            // How many pixels from the left must the form be vissible?
 frmDesign.Top := 100;             // How many pixels from the top must the form be vissible?
 frmDesign.Width := 800;           // The width of you form in pixels
 frmDesign.Height := 500;          // The height of you form in pixels
 frmDesign.Caption := 'Test!';     // The name of your form? This will be shown in the upper left balk
 frmDesign.Color := ClWhite;       // The background color of your form ("ClWhite", "ClBlack" ect, or just an color like: 123456)
 frmDesign.Font.Color := ClBlack;        // The color of the text (Tlabels) when you have those
 frmDesign.Font.Name := 'Comic Sans MS'; // The name of the font you want the Tlabels to be 

 MyScrollBox := TScrollBox.Create(frmDesign);
 MyScrollBox.Parent := frmDesign;
 MyScrollBox.Color := 14145495;
 MyScrollBox.Left := 50;
 MyScrollBox.Top := 50;
 MyScrollBox.Width := 450;
 MyScrollBox.Height := 302;
 MyScrollBox.VertScrollBar.Position := 0;
 MyScrollBox.VertScrollBar.Range := 600;
 MyScrollBox.AutoScroll := False;

 Label1 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label1.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label1.Top := 20;                       // how many pixels from the left
 Label1.Left := 20;                      // how many pixels from the top
 Label1.Caption := 'Item Number : 1';  // What does your label need to say?
 Label1.Font.Size := 17;                 // The size of your text
 Label1.Font.Color := ClRed;             // The color of your text
 Label1.Font.Name := 'Comic Sans MS';    // The font name of your text 

 Label2 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label2.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label2.Top := 60;                       // how many pixels from the left
 Label2.Left := 20;                      // how many pixels from the top
 Label2.Caption := 'Item Number : 2';  // What does your label need to say?
 Label2.Font.Size := 17;                 // The size of your text
 Label2.Font.Color := ClRed;             // The color of your text
 Label2.Font.Name := 'Comic Sans MS';    // The font name of your text

 Label3 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label3.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label3.Top := 100;                       // how many pixels from the left
 Label3.Left := 20;                      // how many pixels from the top
 Label3.Caption := 'Item Number : 3';  // What does your label need to say?
 Label3.Font.Size := 17;                 // The size of your text
 Label3.Font.Color := ClRed;             // The color of your text
 Label3.Font.Name := 'Comic Sans MS';    // The font name of your text

 Label4 := TLabel.Create(FrmDesign);     // This will create the label. Must Be called.
 Label4.Parent := MyScrollBox;             // The parent is very important. Without the parrent set to the formname the label wont be visible
 Label4.Top := 140;                       // how many pixels from the left
 Label4.Left := 20;                      // how many pixels from the top
 Label4.Caption := 'Item Number : 4';  // What does your label need to say?
 Label4.Font.Size := 17;                 // The size of your text
 Label4.Font.Color := ClRed;             // The color of your text
 Label4.Font.Name := 'Comic Sans MS';    // The font name of your text

end;

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

procedure ShowFormModal;
begin
 frmDesign.ShowModal;
end;

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

begin
 SafeInitForm;        // those 2 function are the action form setup. Thise one creates your form
 SafeShowFormModal;  // and this one makes it visible
end.

 

 

Thanks for trying to help and sending me the links for tuts, as they did help me understand what to do :)

Link to comment
Share on other sites

It could still be better watch this. Also this is some of scroll bar controls i was talking about. Note when using Form controls, some have other controls in them. For instance the scroll box has a TScrollBar control in it. One called VertScrollBar, and another probably called HorizScrollbar or something.

 

[sCAR]

MyScrollBox.VertScrollBar.Position := 0;

MyScrollBox.VertScrollBar.Range := 600;

[/sCAR]

 

Try this:

 

[sCAR]

program New;

 

 

var

frmDesign: TForm;

Label1, Label2, Label3, Label4: TLabel;

MyScrollBox: TScrollBox;

MyTimer: TTimer;

 

procedure ChangeColors(Sender: TObject);

begin

Label1.Font.Color := Random(999);

Label2.Font.Color := Random(999);

Label3.Font.Color := Random(999);

Label4.Font.Color := Random(999);

end;

 

procedure InitForm;

begin

frmDesign := CreateForm; // This will create your form. MUST be called first.

with frmDesign do

begin

Left := 100; // How many pixels from the left must the form be vissible?

Top := 100; // How many pixels from the top must the form be vissible?

Width := 800; // The width of you form in pixels

Height := 500; // The height of you form in pixels

Caption := 'Test!'; // The name of your form? This will be shown in the upper left balk

Color := ClWhite; // The background color of your form ("ClWhite", "ClBlack" ect, or just an color like: 123456)

Font.Color := ClBlack; // The color of the text (Tlabels) when you have those

Font.Name := 'Comic Sans MS'; // The name of the font you want the Tlabels to be

end;

MyScrollBox := TScrollBox.Create(frmDesign);

with MyScrollBox do

begin

Parent := frmDesign;

Color := 14145495;

Left := 50;

Top := 50;

Width := 450;

Height := 302;

VertScrollBar.Position := 0;

VertScrollBar.Range := 600;

AutoScroll := False;

end;

Label1 := TLabel.Create(FrmDesign); // This will create the label. Must Be called.

with Label1 do

begin

Parent := MyScrollBox; // The parent is very important. Without the parrent set to the formname the label wont be visible

Top := 20; // how many pixels from the left

Left := 20; // how many pixels from the top

Caption := 'Item Number : 1'; // What does your label need to say?

Font.Size := 17; // The size of your text

Font.Color := ClRed; // The color of your text

Font.Name := 'Comic Sans MS'; // The font name of your text

end;

 

// etc - LordJashin

Label2 := TLabel.Create(FrmDesign); // This will create the label. Must Be called.

Label2.Parent := MyScrollBox; // The parent is very important. Without the parrent set to the formname the label wont be visible

Label2.Top := 60; // how many pixels from the left

Label2.Left := 20; // how many pixels from the top

Label2.Caption := 'Item Number : 2'; // What does your label need to say?

Label2.Font.Size := 17; // The size of your text

Label2.Font.Color := ClRed; // The color of your text

Label2.Font.Name := 'Comic Sans MS'; // The font name of your text

 

Label3 := TLabel.Create(FrmDesign); // This will create the label. Must Be called.

Label3.Parent := MyScrollBox; // The parent is very important. Without the parrent set to the formname the label wont be visible

Label3.Top := 100; // how many pixels from the left

Label3.Left := 20; // how many pixels from the top

Label3.Caption := 'Item Number : 3'; // What does your label need to say?

Label3.Font.Size := 17; // The size of your text

Label3.Font.Color := ClRed; // The color of your text

Label3.Font.Name := 'Comic Sans MS'; // The font name of your text

 

Label4 := TLabel.Create(FrmDesign); // This will create the label. Must Be called.

Label4.Parent := MyScrollBox; // The parent is very important. Without the parrent set to the formname the label wont be visible

Label4.Top := 140; // how many pixels from the left

Label4.Left := 20; // how many pixels from the top

Label4.Caption := 'Item Number : 4'; // What does your label need to say?

Label4.Font.Size := 17; // The size of your text

Label4.Font.Color := ClRed; // The color of your text

Label4.Font.Name := 'Comic Sans MS'; // The font name of your text

 

MyTimer := TTimer.Create(frmDesign);

with MyTimer do

begin

Enabled := True;

Interval := 1000;

OnTimer := @ChangeColors;

end;

end;

 

procedure SafeInitForm;

var

v: TVariantArray;

begin

setarraylength(V, 0);

ThreadSafeCall('InitForm', v);

end;

 

procedure ShowFormModal;

begin

frmDesign.ShowModal;

end;

 

procedure SafeShowFormModal;

var

v: TVariantArray;

begin

setarraylength(V, 0);

ThreadSafeCall('ShowFormModal', v);

end;

 

begin

SafeInitForm; // those 2 function are the action form setup. Thise one creates your form

SafeShowFormModal; // and this one makes it visible

end.

[/sCAR]

Link to comment
Share on other sites

It could still be better watch this. Also this is some of scroll bar controls i was talking about. Note when using Form controls, some have other controls in them. For instance the scroll box has a TScrollBar control in it. One called VertScrollBar, and another probably called HorizScrollbar or something.

 

[sCAR]

MyScrollBox.VertScrollBar.Position := 0;

MyScrollBox.VertScrollBar.Range := 600;

[/sCAR]

 

 

Ye I understand what you meant now, I didnt know they had there own objects built into them, so I was trying to link two together which is why I was getting all confused and going wrong.

 

Your coloured writing thing is really good! Thanks for showing me that too, mind if I use it in the future?

Link to comment
Share on other sites

Ye I understand what you meant now, I didnt know they had there own objects built into them, so I was trying to link two together which is why I was getting all confused and going wrong.

 

Your coloured writing thing is really good! Thanks for showing me that too, mind if I use it in the future?

 

Well here's a tutorial on TTimers:

 

Interval is the time in Milliseconds (1000 miliseconds = 1 second).

So Time in MS, once that time is reached the OnTimer event is triggered which will go and run TimerEvent.

Enabled is a variable you have to set to True in order for the Timer to start working.

OnTimer, is the event. If you type TTimer with a dot in SCAR Divi and hit CTRL + Space and then type OnTimer, it will show up as this: OnTimer: TNotifyEvent; A TNotifyEvent is defined as having (Sender: TObject) as the params.

We use this @TimerEvent, because we are passing the object calling that (the sender) to that procedure. So inside the TimerEvent we could put...if Sender = myTimer then i := i + 1; or something.

[sCAR]

myTimer := TTimer.Create(myForm);

with myTimer do

begin

Enabled := True;

Interval := 1000;

onTimer := @TimerEvent;

end;

[/sCAR]

 

I learned the color thing from someone else too so yeah you can use it lol.

 

Note instead of doing Font.Color := Random(999); ( Red colors usually and black) you could make your own array of "cl" colors: clBlack, clRed, clYellow, etc. Then do something like Font.Color := ColorArray[Random(high(ColorArray)];

 

High returns the highest index of the array. The index is the number between the [] like:

ColorArray[3] := clYellow;

Edited by LordJashin
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...