Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 12:27 PM, Graeme Geldenhuys graemeg.li...@gmail.com wrote: On 14/09/2011 23:17, Marcos Douglas wrote: procedure Run; var f: TFoo; // type is class, not interface o: TObj; begin f := TFoo.Create; This is just wrong. 1 - If i use the class not Interface is the recount used? 2 - Is that compatible with Delphi? In 1 i meant, as i expected if i use f:IFoo the refcount counted, but if i use f:TFoo methods of reference not triggered? Thanks Zaher Dirkey ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: How to detect supported data types in dataset?
On 8-9-2011 9:16, michael.vancanneyt-0is9kj9s...@public.gmane.org wrote: On Thu, 8 Sep 2011, Reinier Olislagers wrote: Am I missing something obvious or does it make sense to expose something like a SupportedFieldTypes property for datasets? How does Delphi do this? It does not. Besides that, I think it's an excellent idea to check for invalid datatypes when creating fields, rather than failing later on when assigning values to them. It is up to the implementation of the datasets to give a decent error when an unsupported data type is being created. Ok, thanks, I'll raise bug reports for the relevant datasets when I hit that problem again... Reinier ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On 14 Sep 2011, at 23:17, Marcos Douglas wrote: BUT, if I create my TFoo without refcount should works, right? Only in some circumstances. These circumstances depend on when the compiler allocates temporary interface instances, and when these are finalized. ... but, does not work. In Delphi 7 yes, but no in FPC. It also works in FPC if you remove heaptrc. What happens is a) the compiler creates a temporary copy of the interface instance at some point in the code b) you free the underlying object and heaptrc overwrites its memory with 0xf0f0f0f0 c) at the end of the routine, the compiler tries to finalize the temporary interface instance. This crashes because the interface instance no longer contains valid data Without heaptrc, the example happens to work because the freed memory of the instance hasn't been reallocated and overwritten yet. It's not safe in general though. The answer is: the hack with returning -1 from _AddRef and _Release, while documented by Embarcadero, is unsafe because it depends on implementation details. Do not use it. Instead, if you do not want reference-counted interfaces, use {$interfaces corba} instead as mentioned earlier in this thread. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] WinCE multithreading
Yes, the current FPC has this feature. Maybe the problem with WinCE with multithreading is this: http://bugs.freepascal.org/view.php?id=18756 and not the use or not of Unaligned keyword. Added with some outdated documentation on Wiki, this cause a little of confusion in the mind of who starts with WinCE with a multi-thread application. I changed the issue. Testing now to see how it works. The best regards, Fabio Luis Girardi PascalSCADA Project http://sourceforge.net/projects/pascalscada http://www.pascalscada.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] How to get a data module to notify of events?
I have a form with some threaded objects that notify another form of events by calling one of that forms events. I want to convert to a data module and any interested object to register for those notifications. My idea is for each thread to have some kind of list of procedure types and each interested object registers its routine eg. This is the data module. It is a rough sketch and may have some syntax errors Type TOneArg = Procedure (Var X : integer); type TMonitorObject = class(TThread) private InterestedObjects: TList procedure DispatchOutput; procedure DisplayRawOutput; protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); RegisterInterest(interestedProc:TOneArg); end; TMonitorObject.RegisterInterest(TOneArg); begin InterestedObjects.Add(interestedProc); end; procedure TMonitorObject.DispatchOutput; begin foreach InterestedObject do InterestedObject.Procedure.Execute; end; constructor TMonitorObject.Create(CreateSuspended: Boolean); begin inherited Create(CreateSuspended); InterestedObjects := TList.Create FCycleComplete := True; end; Do the procedures for the objects which require notification need to be constructed in some way? Am I on the right track here? I am particularly interested in what happens when the objects passing the routines are destroyed without the data module knowing about it. -- Frank Church === http://devblog.brahmancreations.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get a data module to notify of events?
On Thursday 15 September 2011 16:28:29 Frank Church wrote: I have a form with some threaded objects that notify another form of events by calling one of that forms events. I want to convert to a data module and any interested object to register for those notifications. My idea is for each thread to have some kind of list of procedure types and each interested object registers its routine eg. This is the data module. It is a rough sketch and may have some syntax errors Type TOneArg = Procedure (Var X : integer); type TMonitorObject = class(TThread) private InterestedObjects: TList procedure DispatchOutput; procedure DisplayRawOutput; protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); RegisterInterest(interestedProc:TOneArg); end; TMonitorObject.RegisterInterest(TOneArg); begin InterestedObjects.Add(interestedProc); end; procedure TMonitorObject.DispatchOutput; begin foreach InterestedObject do InterestedObject.Procedure.Execute; end; constructor TMonitorObject.Create(CreateSuspended: Boolean); begin inherited Create(CreateSuspended); InterestedObjects := TList.Create FCycleComplete := True; end; Do the procedures for the objects which require notification need to be constructed in some way? MSEgui has such a notification mechanism with automatic unlinking by destroying the objects, see tobjectlinker in lib/common/kernel/mseclasses.pas. Another possibility is to use a tobjectevent descendant and application.postevent. Am I on the right track here? I am particularly interested in what happens when the objects passing the routines are destroyed without the data module knowing about it. The program most likely will crash. :-) Martin ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get a data module to notify of events?
On 15 September 2011 15:48, Martin Schreiber mse00...@gmail.com wrote: On Thursday 15 September 2011 16:28:29 Frank Church wrote: I have a form with some threaded objects that notify another form of events by calling one of that forms events. I want to convert to a data module and any interested object to register for those notifications. My idea is for each thread to have some kind of list of procedure types and each interested object registers its routine eg. This is the data module. It is a rough sketch and may have some syntax errors Type TOneArg = Procedure (Var X : integer); type TMonitorObject = class(TThread) private InterestedObjects: TList procedure DispatchOutput; procedure DisplayRawOutput; protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); RegisterInterest(interestedProc:TOneArg); end; TMonitorObject.RegisterInterest(TOneArg); begin InterestedObjects.Add(interestedProc); end; procedure TMonitorObject.DispatchOutput; begin foreach InterestedObject do InterestedObject.Procedure.Execute; end; constructor TMonitorObject.Create(CreateSuspended: Boolean); begin inherited Create(CreateSuspended); InterestedObjects := TList.Create FCycleComplete := True; end; Do the procedures for the objects which require notification need to be constructed in some way? MSEgui has such a notification mechanism with automatic unlinking by destroying the objects, see tobjectlinker in lib/common/kernel/mseclasses.pas. Another possibility is to use a tobjectevent descendant and application.postevent. Am I on the right track here? I am particularly interested in what happens when the objects passing the routines are destroyed without the data module knowing about it. The program most likely will crash. :-) I want to know if my approach is a workable one and what the right syntax should be, handling the destroyed objects I believe I can deal with by checking for the existence of the object before notifying it. Are there some examples of that somewhere? Martin ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- Frank Church === http://devblog.brahmancreations.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 6:27 AM, Graeme Geldenhuys graemeg.li...@gmail.com wrote: On 14/09/2011 23:17, Marcos Douglas wrote: procedure Run; var f: TFoo; // type is class, not interface o: TObj; begin f := TFoo.Create; This is just wrong. Well, wrong just because the language is so but not because is ilogical, right? On a side note: --- Why not simply use CORBA interfaces, then you don't need to add the IUnknown or IInterface interface method noise to your class declaration. CORBA interfaces are not reference counted. eg: unit myunit; {$mode objfpc}{$H+} {$interfaces corba} Hm... interesting but what are the advantages? I want my code compiling in Delphi 7 too, so I can have problems with this? The TInterfacedObject class is the most used in many codes (like Zeos for example) and it works. I do not want problems, incompatibilities, confusion, etc http://free-pascal-general.1045716.n5.nabble.com/Corba-Interfaces-and-IInterface-query-td3264311.html Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 9:18 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 14 Sep 2011, at 23:17, Marcos Douglas wrote: BUT, if I create my TFoo without refcount should works, right? Only in some circumstances. These circumstances depend on when the compiler allocates temporary interface instances, and when these are finalized. ... but, does not work. In Delphi 7 yes, but no in FPC. It also works in FPC if you remove heaptrc. What happens is a) the compiler creates a temporary copy of the interface instance at some point in the code b) you free the underlying object and heaptrc overwrites its memory with 0xf0f0f0f0 c) at the end of the routine, the compiler tries to finalize the temporary interface instance. This crashes because the interface instance no longer contains valid data Without heaptrc, the example happens to work because the freed memory of the instance hasn't been reallocated and overwritten yet. It's not safe in general though. Ok, now I understood. The answer is: the hack with returning -1 from _AddRef and _Release, while documented by Embarcadero, is unsafe because it depends on implementation details. Do not use it. Instead, if you do not want reference-counted interfaces, use {$interfaces corba} instead as mentioned earlier in this thread. I know that is a hack... just was an example. About CORBA I think did you answer my question before (I asked Graeme about it). But if no have reference-counted how I release a reference, just use ref := nil? I will search -- and test -- about it, thanks. Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get a data module to notify of events?
On Thursday 15 September 2011 16:53:35 Frank Church wrote: Are there some examples of that somewhere? http://svn.berlios.de/viewvc/mseide-msegui/trunk/lib/common/kernel/mseclasses.pas?view=markup ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 4:54 PM, Marcos Douglas m...@delfire.net wrote: f := TFoo.Create; This is just wrong. Well, wrong just because the language is so but not because is ilogical, right? I don't understand why it would be wrong. For me it seams correct and similar to this example: http://wiki.lazarus.freepascal.org/How_To_Use_Interfaces_to_write_less_code I want my code compiling in Delphi 7 too, so I can have problems with this? You can always use {$ifndef fpc} and {$ifdef fpc} to write code specific to Delphi or FPC -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get a data module to notify of events?
On Thursday 15 September 2011 16:53:35 Frank Church wrote: Are there some examples of that somewhere? or http://svn.berlios.de/viewvc/mseide-msegui/trunk/lib/common/kernel/msegui.pas?view=markup tmethodlist. Warning, tmethodlist.remove() must be called before destroying the registered objects. There is no automatic unliking as in tobjectlinker. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get a data module to notify of events?
On 15 September 2011 16:26, Martin Schreiber mse00...@gmail.com wrote: On Thursday 15 September 2011 16:53:35 Frank Church wrote: Are there some examples of that somewhere? or http://svn.berlios.de/viewvc/mseide-msegui/trunk/lib/common/kernel/msegui.pas?view=markup tmethodlist. Warning, tmethodlist.remove() must be called before destroying the registered objects. There is no automatic unliking as in tobjectlinker. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal Where is the tmethodlist itself defined? -- Frank Church === http://devblog.brahmancreations.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] WinCE multithreading
Hi! I made some changes for WinCE and want test. How I rebuild only the RTL on windows? I'm using WinXP, Lazarus 0.9.30.1 with fpc 2.4.4 + cross-arm downloaded from daily snapshots. The best regards, Fabio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 12:12 PM, Felipe Monteiro de Carvalho felipemonteiro.carva...@gmail.com wrote: On Thu, Sep 15, 2011 at 4:54 PM, Marcos Douglas m...@delfire.net wrote: f := TFoo.Create; This is just wrong. Well, wrong just because the language is so but not because is ilogical, right? I don't understand why it would be wrong. For me it seams correct and similar to this example: http://wiki.lazarus.freepascal.org/How_To_Use_Interfaces_to_write_less_code Yeah, you're right... I didn't see this link. =) But see it one more time: the R instance of TRealClass is not released... saw? I didn't test but I think if R was released will occur an AV. I want my code compiling in Delphi 7 too, so I can have problems with this? You can always use {$ifndef fpc} and {$ifdef fpc} to write code specific to Delphi or FPC Yes, but if I can do this using only one code is better than use conditionals, don't you? Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 12:12 PM, Felipe Monteiro de Carvalho felipemonteiro.carva...@gmail.com wrote: I don't understand why it would be wrong. For me it seams correct and similar to this example: http://wiki.lazarus.freepascal.org/How_To_Use_Interfaces_to_write_less_code I'd like to use the same idea of link above, ie, using a real class (and your's own methods and properties) but assign the instance of this object, in an interface. But, like the link, if I can not use Free method on my objects... well, I think this is strange. What I want was: Two classes completly different but that implement the same interface... and these classes will be instanciated using variables with the same type. To solve my problem, the only way is create more interfaces -- and more code, unfortunately. See below. 'a' and 'b' are different objects, different methods, but they share the same methods, ie, GetInfo and SetInfo. program p1; {$apptype console} {$ifdef FPC} {$mode objfpc}{$H+} {$endif} uses heaptrc, Classes, SysUtils; type IInfo = interface ['{F71A4131-E0A5-48CB-B563-7BBB079D1085}'] function GetInfo: string; procedure SetInfo(const AValue: string); end; IInfoA = interface(IInfo) ['{0E816EA4-21A5-49B3-B7E8-396E2F788E4B}'] procedure SetName(const AValue: string); end; IInfoB = interface(IInfo) ['{0E816EA4-21A5-49B3-B7E8-396E2F788E4B}'] procedure SetNumber(const AValue: Integer); end; TInfo = class(TInterfacedObject, IInfo) private FInfo: string; public function GetInfo: string; procedure SetInfo(const AValue: string); end; TInfoA = class(TInfo, IInfoA) public procedure SetName(const AValue: string); end; TInfoB = class(TInfo, IInfoB) public procedure SetNumber(const AValue: Integer); end; TObj = class(TObject) Info: IInfo; end; { TInfo } function TInfo.GetInfo: string; begin Result := FInfo; end; procedure TInfo.SetInfo(const AValue: string); begin FInfo := AValue; end; { TInfoA } procedure TInfoA.SetName(const AValue: string); begin SetInfo('InfoA :: ' + AValue); end; procedure TInfoB.SetNumber(const AValue: Integer); begin SetInfo('InfoB :: ' + IntToStr(AValue)); end; procedure Run; var a: IInfoA; b: IInfoB; o: TObj; begin a := TInfoA.Create; a.SetName('ZEOS'); b := TInfoB.Create; b.SetNumber(99); o := TObj.Create; o.Info := a; writeln(o.Info.GetInfo); o.Info := b; writeln(o.Info.GetInfo); o.Free; end; begin Run; end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface, _AddRef, _Release, etc.
On Thu, Sep 15, 2011 at 4:45 PM, Marcos Douglas m...@delfire.net wrote: Yeah, you're right... I didn't see this link. =) But see it one more time: the R instance of TRealClass is not released... saw? I didn't test but I think if R was released will occur an AV. As I said, if we use R.Free... W:\dev\tests\interfaces\p2p2.exe Using regular interfaces TBaseObject DoAll ! Got interface OK. Calling it THook Doing something ! TBaseObject DoAll ! Integer GMax:56 Double GMax: 5.65E+001 An unhandled exception occurred at $2D414635 : EAccessViolation : Access violation $2D414635 $00406802 TOBJECT__FREE, line 165 of W:/md/dev/freepascal/compiler/2.4.5/rtl /inc/objpas.inc Heap dump by heaptrc unit 59 memory blocks allocated : 1227/1440 55 memory blocks freed : 1107/1320 4 unfreed memory blocks : 120 True heap size : 229376 (112 used in System startup) True free heap : 228832 Should be : 22 Call trace for block $0006D1B8 size 64 $00408168 REALLOCMEM, line 303 of W:/md/dev/freepascal/compiler/2.4.5/rtl/in c/heap.inc $00407301 fpc_raiseexception, line 196 of W:/md/dev/freepascal/compiler/2.4. 5/rtl/inc/except.inc $00412C75 RUNERRORTOEXCEPT, line 369 of W:/md/dev/freepascal/compiler/2.4.5/ rtl/objpas/sysutils/sysutils.inc $00407C5E HANDLEERRORADDRFRAME, line 901 of W:/md/dev/freepascal/compiler/2. 4.5/rtl/inc/system.inc $00406802 TOBJECT__FREE, line 165 of W:/md/dev/freepascal/compiler/2.4.5/rtl /inc/objpas.inc $0040BAA1 EXE_ENTRY, line 376 of system.pp Call trace for block $00056340 size 24 $00407301 fpc_raiseexception, line 196 of W:/md/dev/freepascal/compiler/2.4. 5/rtl/inc/except.inc $00412C75 RUNERRORTOEXCEPT, line 369 of W:/md/dev/freepascal/compiler/2.4.5/ rtl/objpas/sysutils/sysutils.inc $00407C5E HANDLEERRORADDRFRAME, line 901 of W:/md/dev/freepascal/compiler/2. 4.5/rtl/inc/system.inc $00406802 TOBJECT__FREE, line 165 of W:/md/dev/freepascal/compiler/2.4.5/rtl /inc/objpas.inc $0040BAA1 EXE_ENTRY, line 376 of system.pp Call trace for block $000562E0 size 16 $00412A87 RUNERRORTOEXCEPT, line 349 of W:/md/dev/freepascal/compiler/2.4.5/ rtl/objpas/sysutils/sysutils.inc $00407C5E HANDLEERRORADDRFRAME, line 901 of W:/md/dev/freepascal/compiler/2. 4.5/rtl/inc/system.inc $00406802 TOBJECT__FREE, line 165 of W:/md/dev/freepascal/compiler/2.4.5/rtl /inc/objpas.inc $0040BAA1 EXE_ENTRY, line 376 of system.pp Call trace for block $00056220 size 16 $00401796 main, line 104 of p2.lpr $0040BAA1 EXE_ENTRY, line 376 of system.pp $00407924 fpc_initializeunits, line 753 of W:/md/dev/freepascal/compiler/2.4 .5/rtl/inc/system.inc $0040BAA1 EXE_ENTRY, line 376 of system.pp W:\dev\tests\interfaces\p2 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Multiple enumerators per class
Hi all, I found the Wiki page about the new for-in loop and found a misinformation. It stated wrongly that it is not possible to have multiple enumerators per class. It even gave a proposal for a new feature that did not add anything new. I added an example how to add a second enumerator to a class: http://wiki.freepascal.org/for-in_loop#Multiple_enumerators_for_one_class IMO the proposal was misleading so I deleted it. I hope this is ok. If not, I will restore it. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Multiple enumerators per class
On Thu, Sep 15, 2011 at 6:37 PM, Mattias Gaertner nc-gaert...@netcologne.de wrote: Hi all, I found the Wiki page about the new for-in loop and found a misinformation. It stated wrongly that it is not possible to have multiple enumerators per class. It even gave a proposal for a new feature that did not add anything new. I added an example how to add a second enumerator to a class: http://wiki.freepascal.org/for-in_loop#Multiple_enumerators_for_one_class IMO the proposal was misleading so I deleted it. I hope this is ok. If not, I will restore it. Mattias How can you use multiple enumerators? I searched it recently and only found that wiki page ;-) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Multiple enumerators per class
On Thu, 15 Sep 2011 18:52:30 -0300 Flávio Etrusco flavio.etru...@gmail.com wrote: On Thu, Sep 15, 2011 at 6:37 PM, Mattias Gaertner nc-gaert...@netcologne.de wrote: Hi all, I found the Wiki page about the new for-in loop and found a misinformation. It stated wrongly that it is not possible to have multiple enumerators per class. It even gave a proposal for a new feature that did not add anything new. I added an example how to add a second enumerator to a class: http://wiki.freepascal.org/for-in_loop#Multiple_enumerators_for_one_class IMO the proposal was misleading so I deleted it. I hope this is ok. If not, I will restore it. Mattias How can you use multiple enumerators? I searched it recently and only found that wiki page ;-) That's why I added the example. ;) Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal