SRL Archive - Test corner

Declare a Type in a procedure or function :)


SKy Scripter

2007-10-02 13:45:10

So you want to declare types in functions and procedures eh?


Well, i thought i would share this… you can declare types in functions and procedures :D


function TestString(i : Integer) : string;
var
S : record
ss : string;
number : Integer;
end;
State : (True, False, Maybe);
begin
with s do
case i of
1 : begin
s.ss := 'number 1';
s.number := 2;
state := True;
end;
2 : begin
s.ss := 'number 2';
s.number := 4;
State := maybe;
end;
end;
if (state = state) then
result := s.ss;
end;

also you can do double layers


type
TSss = record
s : record
v, ss : string;
end;
l : Integer;
end;

mastaraymond

2007-10-02 14:22:55

I've tried this before, but it didn't work o,0 how come you always get it working? You small hacker! Next step is a procedure in a procedure o/

~Raymond

n3ss3s

2007-10-02 14:36:07

Next step is a procedure in a procedure o/

Speaking of which, is it possible? lol… I guess labels are like procedures inside procedures.

State : (True, False, Maybe);


I can do basic stuff with types, but why is that not inside the "Type - end" ?

And why isnt it just State: Boolean :D

SKy Scripter

2007-10-02 14:50:31

type
Boolean = (true, false);


:)

and sense im declaring a type in a procedure / function you dont need "type".

also i chose to (maybe, true, false); to show you that you can do that. -.- :p

mastaraymond

2007-10-02 15:28:10

From: SKy Scripter
type
Boolean = (true, false);


:)

and sense im declaring a type in a procedure / function you dont need "type".

also i chose to (maybe, true, false); to show you that you can do that. -.- :p


Sssst, sky you are telling them every secret of scar ;).

@n3ss3s, In delphi you can declare a procedure\function IN a procedure ^^. Bit useless but cool ^^.

SKy Scripter

2007-10-02 16:55:06

not every secret :rolleyes:

ShowerThoughts

2007-10-02 16:58:32

From: SKy Scripter
not every secret :rolleyes:


ps. dont tell him i am kaitnieks :p

the scar noob

2007-10-02 17:02:20

From: n3ss3s
Speaking of which, is it possible? lol… I guess labels are like procedures inside procedures.



I don't know if I can agree with you.
When you use labels, you go to a given place inside your procedure/function (were you have first loaded the label).
This is what I understood about them, so actually it doesn't calls something "outside" that procedure/function.

-Stijn.

ShowerThoughts

2007-10-02 17:19:28

ehm, sorry it sounds nooby but can some1 discripe the whole function then i can learn from it like after each line a // with explainaition ;) thanks!

Dark_Sniper

2007-10-02 17:38:48

hey sky i wasent able to do that before XD


is it because of scar updates that you can do it now ?

SKy Scripter

2007-10-02 17:41:06

nope you didnt do it right works fine in SCAR 2.03 :p

Santa_Clause

2007-10-02 19:59:34

Wait, so you can now have local types instead of global types?

Widget

2007-10-02 20:54:51

You could always… I've been using them for awhile :P

The Claw

2007-10-02 23:49:27

with s do

never heard of that before..what does the with mean?

ZephyrsFury

2007-10-03 00:10:38


with Players[CurrentPlayer] do
begin
Name := 'blabla';
Pass := 'albalb';
Nick :='....';
//etc..
end;

Its just a short hand way of writing:


Players[CurrentPlayer].Name := 'blabla';
Players[CurrentPlayer].Pass := 'albalb';
Players[CurrentPlayer].Nick := '....';

Correct me if I'm wrong.

The Claw

2007-10-03 00:29:38

then shouldnt he have just done:

function TestString(i : Integer) : string;
var
S : record
ss : string;
number : Integer;
end;
State : (True, False, Maybe);
begin
with s do
case i of
1 : begin
ss := 'number 1';
number := 2;
state := True;
end;
2 : begin
ss := 'number 2';
number := 4;
State := maybe;
end;
end;
if (state = state) then
result := s.ss;
end;

Santa_Clause

2007-10-04 07:22:34

Haha…SKy made a mistake :)

ZephyrsFury

2007-10-04 08:16:51

From: Santa_Clause
Haha…SKy made a mistake :)


No it doesn't compile if you remove the 's.'. Something to do with an internal error (20). I don't know why. Even if I change it to this:


function TestString(i : Integer) : string;
var
S : record
ss : string;
number : Integer;
end;
State : (True, False, Maybe);
begin
case i of
1 : begin
with s do
begin
ss := 'number 1';
number := 2;
end;
state := True;
end;
2 : begin
with s do
begin
ss := 'number 2';
number := 4;
end;
state := maybe;
end;
end;
if (state = state) then
result := s.ss;
end;


It doesn't work.

Starblaster100

2007-10-04 11:24:46

Its because it is a custom Type… usually it would work… its a limitation in SCAR

Wanted

2007-10-07 16:58:30

Yes, with only works for supported classes.

Press F1 while having SCAR open.

Supported classes

This is only a list of some of classes that can be used in SCAR. For more help on properties and methods of individual classes consult Delphi help or internet search. Remember that only very limited functionality is implemented and many properties and methods that work in Delphi will not work in SCAR. Not all supported classes are listed here, only the main ones.

TGroupBox - The TGroupBox component represents a standard group box, used to group related controls on a form.

TLabel - Use TLabel to add text or a bitmap that the user can’t edit to a form.

TEdit - Use a TEdit object to put a standard edit control on a form.

TMemo - Use TMemo to put a standard multiline edit control on a form.

TComboBox - A TComboBox component is an edit box with a scrollable drop-down list attached to it.

TButton - Use TButton to put a standard push button on a form.

TCheckBox - A TCheckBox component presents an option for the user.

TRadioButton - Use TRadioButton to add a radio button to a form.

TListBox - Use TListBox to display a scrollable list of items that users can select, add, or delete.

TScrollBar - Use TScrollBar to add a free-standing scroll bar to a form.

TImage - Use TImage to display a graphical image on a form.

TPanel - Use TPanel to put an empty panel on a form.

TTimer - TTimer is used to simplify calling the system timer functions.

TForm - form (window) component.

TApplication - TApplication encapsulates a windowed application.

TMenuItem - Use TMenuItem to specify the appearance and behavior of an item in a menu.

TMenu - Use TMenu as a base class when defining a component that represents a collection of menu items.

TMainMenu - Use TMainMenu to provide the main menu for a form.

TPopupMenu - Use TPopupMenu to define the pop-up menu that appears when the user clicks on a control with the right mouse button.

TCanvas - Use TCanvas as a drawing surface for objects that draw an image of themselves.

TProgressBar - Use TProgressBar to add a progressbar to a form.

TRichEdit - Use TRichEdit to add a RichEdit textbox to a form.

TPageControl - Use TPageControl to add a pagecontrol to a form.

TTabControl - Use TTabControl to add a tabcontrol to a form.

TTabSheet - Use TTabSheet to add a tab to a pagecontrol or tabcontrol.

TStatusBar - Use TStatusBar to add a statusbar to a form.

TStatusPanel - Use TStatusPanel to add a panel to a statusbar.

TColorPicker - Use TColorPicker to create a ColorPicker control.

ZephyrsFury

2007-10-07 22:49:08

Right I see, thanks for clearing it up.

jhildy

2007-10-08 21:17:42

Ha i thought most people knew this. I tried it a while ago and didn't really think it was that cool because i have never had to use a local custom type but whatever. I guess good discovery.