Thanks.
Bob B.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150726/fe1bf0c8/attachment.html>

Mailing lists / lazarus / 2015-07
15 messages · 8 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Thanks.
Bob B.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150726/fe1bf0c8/attachment.html>
If you typecast something you can use the fields and properties of the type you use for casting, for example:
if TCheckBox(Sender).Checked then {do_something} ;or
if TCheckBox(Components[I]).Checked then {do_something} ;2015-07-27 00:31 keltez?ssel, Bob B. ?rta:
Sorry!
I was "misreading" your mail... you want to know the type of them.
You can compare the type of them:
if Sender = TButton then { do something} ;or you can get the name of the class
ShowMessage( Sender.classname );2015-07-27 07:30 keltez?ssel, P?ter G?bor ?rta:
The correct operator is "is" not "=".
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150727/7b6d2ea6/attachment.html>
Sorry! I was "misreading" your mail... you want to know the type of them. You can compare…
Can this be elegantly put into a case statement?
Hi, I just tried it and no you can't. At least not directly, there may be a way of casting the Sender object to ordinal or string but I'm not sure that is efficient or elegant.
Why not simply iterate the control List:
for i := 0 to Controls.Count - 1 do
begin
If controls[ i ] is TCheckbox then
TCheckbox( Controls[ i ] ).Checked := ....
end;I didn't think there was, but thought it worth asking. My use case is this sort of thing:
if MainForm.OutputComponent is TListBox then
with MainForm.ListBox1 do begin
Font.Name := fontName;
Font.Size := fontSize
end;
if MainForm.OutputComponent is TMemo then
with MainForm.Memo1 do begin
Font.Name := fontName;
Font.Size := fontSize
end;
...Now obviously I could have a separate property holding an enumeration, but it's a pity that it's not possible to do something like
case MainForm.OutputComponent of
TListBox: begin end;
TMemo: begin end;
...
otherwise
// Fatal exception since this is a serious programming error
end;You can:
Case Lowercase(MainForm.OutputComponent.Classname) of
'tlistbox' : begin end;
'tmemo' : begin end;Michael.
Can this be elegantly put into a case statement? Mark Morgan Lloyd markMLl .AT.…
If you use the classname property you can:
case Sender.classname of
'TCheckBox': ShowMessage('This is a TCheckBox');
end;2015-07-27 09:31 keltez?ssel, Mark Morgan Lloyd ?rta:
Good point. I wonder if that's mode-specific (language manual simply says "Free Pascal allows").
Sorry! I was "misreading" your mail... you want to know the type of them. You can compare…
P?ter G?bor wroteif Sender = TButton then { do something} ;
I suppose you meant
if Sender is TButton then { do something} ;OP: If you want to deal with a lot of different classes that might be the sender, it might help to define an array of these classes (types) and search it.
-Michael
I didn't think there was, but thought it worth asking. My use case is this sort of thing:…
If all you need to do is to change the Font you can also just use a cracker class or use a bogus unchecked to e.g. TMemo (accompanied by informative comments ;-) , since Font is declared in TControl.
Regards,
Fl?vio
I suppose you meant if Sender is TButton then { do something} ; OP: If you want to deal…
2015-07-27 13:33 keltez?ssel, Michael Schnell ?rta:
Yes!
Good point. I wonder if that's mode-specific (language manual simply says "Free Pascal…
Am 27.07.2015 12:06 schrieb "Mark Morgan Lloyd" <
"Free Pascal allows").
I'm not aware that it is mode specific. But it will work only with FPC ;)
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150727/032880b3/attachment-0001.html>
I didn't think there was, but thought it worth asking. My use case is this sort of thing:…
Am 27.07.2015 11:37 schrieb "Mark Morgan Lloyd" <
: Now obviously I could have a separate property holding an enumeration,
but it's a pity that it's not possible to do something like
I had already thought about a TClass-case myself, but the first problem is whether the case labels should be strict ("x.ClassType = y") or loose ("x is y") [for Strings and Ordinals that is no problem]. And if the latter, what if the type is a TEdit, but you have labels for example for TCustomEdit and TControl? Also ranges should probably not be allowed (e.g. TControl..TEdit).
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150727/776f9f15/attachment.html>