Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
Am 27.07.2015 11:37 schrieb Mark Morgan Lloyd markmll.laza...@telemetry.co.uk: 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; 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 -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
2015-07-27 13:33 keltezéssel, Michael Schnell írta: I suppose you meant if Sender is TButton then { do something} ; -Michael Yes! -- Péter Gábor p...@freemail.hu -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
Sorry about that - that message was supposed to be sent in reply to a message rhar came in right before one that was for this list. My Note 4 thought I was trying to reply a thread in the Lazarus group. -Chris On Jul 27, 2015 7:23 AM, Chris Kelling kelli...@cox.net wrote: We have one in Room B. It is Ed Sax's old machine. It is an early model that has the chicklett keyboard. About the only distinction tge PC Jr has is that is was a finacial failure. Both style of keyboards are wireless, but you had to have the keyboard aimed directly at the IR receiver on the PC. If it has the newer style keyboard, I say we take it. We can put both styles on display to show the difference. Otherwise, we should pass. -Chris On Jul 27, 2015 6:06 AM, Mark Morgan Lloyd markmll.laza...@telemetry.co.uk wrote: Péter Gábor wrote: If you use the classname property you can: case Sender.classname of 'TCheckBox': ShowMessage('This is a TCheckBox'); end; Good point. I wonder if that's mode-specific (language manual simply says Free Pascal allows). -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
On 07/27/2015 07:47 AM, Péter Gábor wrote: if 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 -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
On Mon, Jul 27, 2015 at 6:37 AM, Mark Morgan Lloyd markmll.laza...@telemetry.co.uk wrote: JuuS wrote: On 07/27/2015 09:31 AM, Mark Morgan Lloyd wrote: Péter Gábor wrote: 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} ; 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. 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; 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 -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
We have one in Room B. It is Ed Sax's old machine. It is an early model that has the chicklett keyboard. About the only distinction tge PC Jr has is that is was a finacial failure. Both style of keyboards are wireless, but you had to have the keyboard aimed directly at the IR receiver on the PC. If it has the newer style keyboard, I say we take it. We can put both styles on display to show the difference. Otherwise, we should pass. -Chris On Jul 27, 2015 6:06 AM, Mark Morgan Lloyd markmll.laza...@telemetry.co.uk wrote: Péter Gábor wrote: If you use the classname property you can: case Sender.classname of 'TCheckBox': ShowMessage('This is a TCheckBox'); end; Good point. I wonder if that's mode-specific (language manual simply says Free Pascal allows). -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
Am 27.07.2015 12:06 schrieb Mark Morgan Lloyd markmll.laza...@telemetry.co.uk: Péter Gábor wrote: If you use the classname property you can: case Sender.classname of 'TCheckBox': ShowMessage('This is a TCheckBox'); end; Good point. I wonder if that's mode-specific (language manual simply says Free Pascal allows). I'm not aware that it is mode specific. But it will work only with FPC ;) Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Owner of a TCanvas
On Mon, Jul 27, 2015 at 6:31 AM, Xiangrong Fang xrf...@gmail.com wrote: Hi There, Can I somehow get the object which owns a Canvas? e.g.: function GetCanvasOwner(ACanvas: TCanvas): TObject; begin Result := ACanvas.Owner; end; pb := TPaintBox(GetCanvasOwner(pb.Canvas); Thanks! Xiangrong You can if the canvas is a TControlCanvas. Luckly TGraphicControl.Canvas is a TControlCanvas, thus one can do e.g.: function GetCanvasOwner(ACanvas: TCanvas): TControl; begin Result := (ACanvas as TControlCanvas).Control; end; Regards, Flávio -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Owner of a TCanvas
On 27/07/2015 10:31, Xiangrong Fang wrote: Hi There, Can I somehow get the object which owns a Canvas? e.g.: function GetCanvasOwner(ACanvas: TCanvas): TObject; begin Result := ACanvas.Owner; end; pb := TPaintBox(GetCanvasOwner(pb.Canvas); A TCanvas does not have a built-in Owner property. It descends from TPersistent, but not from TComponent, the class that introduces Owner and ownership. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
Péter Gábor wrote: If you use the classname property you can: case Sender.classname of 'TCheckBox': ShowMessage('This is a TCheckBox'); end; Good point. I wonder if that's mode-specific (language manual simply says Free Pascal allows). -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TEncoding class
Very good! Regards, Ara -- http://www.fastmail.com - The way an email service should be -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
Péter Gábor wrote: 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} ; Can this be elegantly put into a case statement? -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Sending and receiving record or object data between applications running on different machines.
Hi Travis, Yes, I'm just not sure of the best way to do it with Lazarus. Richard On 26 Jul 2015 17:16, Travis Ayres tray...@gmail.com wrote: If there is a network they share, TCP/IP would work. A client/server architecture. On Jul 26, 2015 2:27 AM, Richard Mace richard.m...@gmail.com wrote: Hi, Can anybody point me at an example of how 2 application's can transfer data between one another across 2 different machines. Thanks Richard PS Lazarus 1.4.2 FPC 2.6.4 windows -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Sending and receiving record or object data between applications running on different machines.
On Mon, 27 Jul 2015, Richard Mace wrote: Hi Travis, Yes, I'm just not sure of the best way to do it with Lazarus. if performance is not an issue: By far the easiest will be to let one app be a HTTP server, the other a HTTP client. If you need high performance, then you should look at protocols like websocket (bauglir websocket) or a simple TCP/IP client server protocol. If the communication is RPC style, I can very much recommend WST. It can handle both HTTP transport and TCP/IP transport. I've been using it for years, it beats some of the commercial products in Delphi. It takes care of the details. Michael. Richard On 26 Jul 2015 17:16, Travis Ayres tray...@gmail.com wrote: If there is a network they share, TCP/IP would work. A client/server architecture. On Jul 26, 2015 2:27 AM, Richard Mace richard.m...@gmail.com wrote: Hi, Can anybody point me at an example of how 2 application's can transfer data between one another across 2 different machines. Thanks Richard PS Lazarus 1.4.2 FPC 2.6.4 windows -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Owner of a TCanvas
Hi There, Can I somehow get the object which owns a Canvas? e.g.: function GetCanvasOwner(ACanvas: TCanvas): TObject; begin Result := ACanvas.Owner; end; pb := TPaintBox(GetCanvasOwner(pb.Canvas); Thanks! Xiangrong -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
JuuS wrote: On 07/27/2015 09:31 AM, Mark Morgan Lloyd wrote: Péter Gábor wrote: 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} ; 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. 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; -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
On Mon, 27 Jul 2015, Mark Morgan Lloyd wrote: JuuS wrote: On 07/27/2015 09:31 AM, Mark Morgan Lloyd wrote: Péter Gábor wrote: 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} ; 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. 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.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
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: Péter Gábor wrote: if Sender = TButton then { do something} ; Can this be elegantly put into a case statement? -- Péter Gábor p...@freemail.hu -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how to get Type of Sender or Components[i] in order to Cast?
On 07/27/2015 09:31 AM, Mark Morgan Lloyd wrote: Péter Gábor wrote: 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} ; 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; -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Sending and receiving record or object data between applications running on different machines.
On 27/07/15 09:31, Richard Mace wrote: Hi Travis, Yes, I'm just not sure of the best way to do it with Lazarus. Richard Please avoid top-posting.(unless you have good reason for it; most email/news readers have a setting of where you start your reply, with others you just scroll down below the quote and type there) Maybe instead of re-inventing a protocol, try looking at ones already in use, or describe what you want it to do and someone would hint. (e.g. what do you want to send/receive, are the machines in same subnet/network, are they p2p communications or one server, multiple clients involved?) Kind Regards el es -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus