Re: [fpc-devel] procedure Types
You could use this: [snip] type TObjThreadFunc = function: PtrInt of object; function BeginObjThread(ThreadFunction: TObjThreadFunc): DWord; begin with TMethod(ThreadFunction) do Result := BeginThread(TThreadFunc(Code), Data); end; [/snip] 2006/3/13, Amir Aavani <[EMAIL PROTECTED]>: > > Any idea to call: > BeginThread (@MyObject.F1, Pointer (S)) > > Michael Van Canneyt wrote: > > >On Sat, 4 Mar 2006, Amir Aavani wrote: > > > > > > > >>I have problem with procedure Types. > >>Look at the following code: > >> > >>TProcedure= procedure (S: String); > >>TTest= class > >>MyF: TProcedure; > >>procedure F1 (S: String); > >>procedure F2 (S: String); > >> > >>... > >>end; > >> > >>TTest.constructor ; > >>begin > >> MyF:= @F1; > >>end; > >> > >>it says it can't cast "Procedure (S: String); Object" to TProcedure. The > >>problem is clear but I don't know > >>(can't find) any solution to define TProcedure as a procedure of a class > >>which > >>accepts one argument. > >> > >> > > > >Try the following (note the 'of object' in the declaration): > > > >Type > > TMyStringProc = procedure (S : String) of object; > > > >and then > >x > > MyF : TMyStringProc; > > > >This is documented. > > > >Michael. > >___ > >fpc-devel maillist - fpc-devel@lists.freepascal.org > >http://lists.freepascal.org/mailman/listinfo/fpc-devel > > > > > > > ___ > fpc-devel maillist - fpc-devel@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-devel > -- Geno Roupsky ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] procedure Types
On Mon, 13 Mar 2006, Amir Aavani wrote: Any idea to call: BeginThread (@MyObject.F1, Pointer (S)) You can't do this. MyObject.F1 is a method, not a procedure. You should do something like: Function MyThreadProc(P : Pointer) : Integer; begin TMyObject(P).F1; end; and call BeginThread (@MyThreadProc,(MyObject)) (don't remember the exact form of the thread function.) Or better yet, use TThread. Michael Van Canneyt wrote: On Sat, 4 Mar 2006, Amir Aavani wrote: I have problem with procedure Types. Look at the following code: TProcedure= procedure (S: String); TTest= class MyF: TProcedure; procedure F1 (S: String); procedure F2 (S: String); ... end; TTest.constructor ; begin MyF:= @F1; end; it says it can't cast "Procedure (S: String); Object" to TProcedure. The problem is clear but I don't know (can't find) any solution to define TProcedure as a procedure of a class which accepts one argument. Try the following (note the 'of object' in the declaration): Type TMyStringProc = procedure (S : String) of object; and then x MyF : TMyStringProc; This is documented. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] procedure Types
Any idea to call: BeginThread (@MyObject.F1, Pointer (S)) Michael Van Canneyt wrote: On Sat, 4 Mar 2006, Amir Aavani wrote: I have problem with procedure Types. Look at the following code: TProcedure= procedure (S: String); TTest= class MyF: TProcedure; procedure F1 (S: String); procedure F2 (S: String); ... end; TTest.constructor ; begin MyF:= @F1; end; it says it can't cast "Procedure (S: String); Object" to TProcedure. The problem is clear but I don't know (can't find) any solution to define TProcedure as a procedure of a class which accepts one argument. Try the following (note the 'of object' in the declaration): Type TMyStringProc = procedure (S : String) of object; and then x MyF : TMyStringProc; This is documented. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] procedure Types
Thanks to Michael and Christian. It works correctly. I think it could be usefull to put an example for this case in fpc docs. Michael Van Canneyt wrote: On Sat, 4 Mar 2006, Amir Aavani wrote: I have problem with procedure Types. Look at the following code: TProcedure= procedure (S: String); TTest= class MyF: TProcedure; procedure F1 (S: String); procedure F2 (S: String); ... end; TTest.constructor ; begin MyF:= @F1; end; it says it can't cast "Procedure (S: String); Object" to TProcedure. The problem is clear but I don't know (can't find) any solution to define TProcedure as a procedure of a class which accepts one argument. Try the following (note the 'of object' in the declaration): Type TMyStringProc = procedure (S : String) of object; and then MyF : TMyStringProc; This is documented. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] procedure Types
On Sat, 4 Mar 2006, Amir Aavani wrote: > > > I have problem with procedure Types. > Look at the following code: > > TProcedure= procedure (S: String); > TTest= class > MyF: TProcedure; > procedure F1 (S: String); > procedure F2 (S: String); > > ... > end; > > TTest.constructor ; > begin > MyF:= @F1; > end; > > it says it can't cast "Procedure (S: String); Object" to TProcedure. The > problem is clear but I don't know > (can't find) any solution to define TProcedure as a procedure of a class which > accepts one argument. Try the following (note the 'of object' in the declaration): Type TMyStringProc = procedure (S : String) of object; and then MyF : TMyStringProc; This is documented. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] procedure Types
On Saturday 04 March 2006 10:09, Amir Aavani wrote: > I have problem with procedure Types. > Look at the following code: > > TProcedure= procedure (S: String); > TTest= class > MyF: TProcedure; > procedure F1 (S: String); > procedure F2 (S: String); > > ... > end; > > TTest.constructor ; > begin > MyF:= @F1; > end; > > it says it can't cast "Procedure (S: String); Object" to TProcedure. The > problem is clear but I don't know > (can't find) any solution to define TProcedure as a procedure of a class > which accepts one argument. You have declared MyF as a TProcedure, so this is just not going to work. Try this instead: type TMyFProc = Procedure(S: String) of Object; ... MyF: TMyFProc; ... that should work. -- Regards, Christian Iversen ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
[fpc-devel] procedure Types
I have problem with procedure Types. Look at the following code: TProcedure= procedure (S: String); TTest= class MyF: TProcedure; procedure F1 (S: String); procedure F2 (S: String); ... end; TTest.constructor ; begin MyF:= @F1; end; it says it can't cast "Procedure (S: String); Object" to TProcedure. The problem is clear but I don't know (can't find) any solution to define TProcedure as a procedure of a class which accepts one argument. Yours Amir ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel