Re: [fpc-pascal] WHY compiler should be public?

2013-10-26 Thread Xiangrong Fang
2013/10/25 Michael Van Canneyt mich...@freepascal.org Why not simply make it a procedure that is called by ver-2 and ver-3. If it cannot be called directly from external code, and will called only from inside a visible consructor, there is simply no reason to make this procedure a

Re: [fpc-pascal] WHY compiler should be public?

2013-10-26 Thread Xiangrong Fang
2013/10/25 Michael Van Canneyt mich...@freepascal.org Why not simply make it a procedure that is called by ver-2 and ver-3. If it cannot be called directly from external code, and will called only from inside a visible consructor, there is simply no reason to make this procedure a

[fpc-pascal] WHY compiler should be public?

2013-10-24 Thread Xiangrong Fang
Hi, First of all, I did some research and found this: http://free-pascal-general.1045716.n5.nabble.com/Compiler-Warning-Constructor-should-be-public-td2825747.html But that did not convince me. So here is my situation and question. I have the following case: TBase = class public constructor

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-29 Thread Xiangrong Fang
2013/9/30 Sven Barth pascaldra...@googlemail.com However, this does not work, because it seems that I cannot make any generic method virtual! In TIntTree, I have to write: function TIntTree.DoClone: TIntTree; As it is not possible to write TTree outside of the generic definition. This

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-28 Thread Xiangrong Fang
2013/9/28 Sven Barth pascaldra...@googlemail.com On second sight your solution is not correct, because you are using Clone inside your parent class which would not use the (non-virtual) Clone you created. ​What If I make Clone virtual? If by adding virtual to Clone, the problem is solved,

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-28 Thread Xiangrong Fang
2013/9/29 Sven Barth pascaldra...@googlemail.com If you want to override the virtual Clone method of TTreeLongInt in TIntTree you need to use the same result type + override or otherwise you gain nothing, because the compiler will not consider the method as overloaded and use the Clone

[fpc-pascal] generic class helper and class references

2013-09-28 Thread Xiangrong Fang
Hi There, While playing with generics (ref. class inheritance and type incompatibility), I have an idea to use generic class helper to overcome the problem that generic methods cannot be virtual (because the compiler see specialized class different than the generic one?) I have a TTree generic

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-28 Thread Xiangrong Fang
2013/9/28 Sven Barth pascaldra...@googlemail.com On second sight your solution is not correct, because you are using Clone inside your parent class which would not use the (non-virtual) Clone you created. I've now played around with 2.6.2 myself and this should solve this problem: ===

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-27 Thread Xiangrong Fang
Hi Sven, 2013/9/26 Sven Barth pascaldra...@googlemail.com As you can see you are constructing a TTreeInteger class inside TTreeInteger.Clone and nothing in the world afterwards can turn it into a TTreeInt. ​Do you mean that casting TTreeInteger into TTreeInt is not possible because this is

[fpc-pascal] class inheritance and type incompatibility

2013-09-26 Thread Xiangrong Fang
Hi All, I have the following program: 1 program test; 2 {$mode objfpc}{$H+} 3 uses tree; 4 type 5 TIntTree = class(specialize TTreeInteger) 6 public 7 function Clone: TIntTree; 8 end; 9 function TIntTree.Clone: TIntTree; 10 begin 11 Result := TIntTree(inherited

[fpc-pascal] Re: class inheritance and type incompatibility

2013-09-26 Thread Xiangrong Fang
2013/9/26 Xiangrong Fang xrf...@gmail.com Which output: TIntTree TIntTree.TTree$LongInt Forgot to ask, I understand that TTree$LongInt is the name the compiler gave to the generic class when it is specialized, but what is TIntTree.TTree$LongInt? What is the meaning of Scoped type (or type

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-26 Thread Xiangrong Fang
What should work is the following (now with generics again): === code begin === type TTreeT = class private type TSelfClass = class of TTree; public function Clone: TTree; end; function TTree.Clone: TTree; begin Result := TSelfClass(Self.ClassType).**Create(Data,

Re: [fpc-pascal] class inheritance and type incompatibility

2013-09-26 Thread Xiangrong Fang
2013/9/26 Sven Barth pascaldra...@googlemail.com ​After change to this code in Clone(), I got this error: ​ ​tree.pas(66,60) Error: Incompatible type for arg no. 2: Got TIntTree.TTree$LongInt, expected TTree Seems like a bug in 2.6.x. It's compiling in 2.7.1. ​I altered the code so

[fpc-pascal] function param and TVarRec

2013-09-24 Thread Xiangrong Fang
Hi There, If you declare this: procedure proc(param: array of const); Then you can pass any type of varaible to param, however, only in an array, such as proc([1, 2]); Is it possible to achieve the effect of the code below (which is wrong): procedure proc(p1: const; p2: const); So that: 1)

Re: [fpc-pascal] function param and TVarRec

2013-09-24 Thread Xiangrong Fang
. This is a trivial problem, I can just go with array of const, I am just curious if pascal can do this, because it will make the function definition more strict and my code cleaner. Regards, Xiangrong 2013/9/24 Michael Van Canneyt mich...@freepascal.org On Tue, 24 Sep 2013, Xiangrong Fang wrote: Hi

[fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Xiangrong Fang
Hi All, say, I have a class TTreeT; in the destructor of that class, is it possible to know the actual type of T? I want to do things like: generic TTreeT = class public Data: T; destructor Destroy; override; end; destructor TTree.Destroy; begin ... ... if Data is TObject then

Re: [fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Xiangrong Fang
But it's not a good idea as you'd still need to convert Data to a TObject (e.g. by using a cast), but that will fail if Data is something else than a pointer-like type... This worked in my TTree class (destructor): if PTypeInfo(TypeInfo(Data))^.Kind = tkObject then TObject(Data).Free; I

Re: [fpc-pascal] Incompatible type for generics?

2013-09-24 Thread Xiangrong Fang
Hi Sven, 2013/9/23 Xiangrong Fang xrf...@gmail.com Short answer: you can't. The same would happen with normal classes. Long answer: You could add an additional method Next to your TIntTree which returns a TIntTree and just do Result := TIntTree(inherited Next); there. I still have

Re: [fpc-pascal] Incompatible type for generics?

2013-09-24 Thread Xiangrong Fang
2013/9/24 Sven Barth pascaldra...@googlemail.com How is PNode declared? What is the exact error? PNode is declared inside TTreap generic class, the source is here: https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas The exact error is: Error: Incompatible types: got

Re: [fpc-pascal] Incompatible type for generics?

2013-09-24 Thread Xiangrong Fang
I know it is same but why no error on the line: for n in sm1.reversed... regards. 在 2013-9-24 下午11:23,Sven Barth pascaldra...@googlemail.com写道: Am 24.09.2013 17:14, schrieb Xiangrong Fang: 2013/9/24 Sven Barth pascaldra...@googlemail.com How is PNode declared? What is the exact error

[fpc-pascal] record byte alignment

2013-09-24 Thread Xiangrong Fang
Hi There, I wonder what is the byte alignment of a NON-packed record? Is it always 4-byte, or 4-byte on 32-bit platform, 8-byte or 64-bit platform? Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] Incompatible type for generics?

2013-09-23 Thread Xiangrong Fang
Short answer: you can't. The same would happen with normal classes. Long answer: You could add an additional method Next to your TIntTree which returns a TIntTree and just do Result := TIntTree(inherited Next); there. Why are you subclassing in this case anyway? Thanks, I will inherit the

Re: [fpc-pascal] bridging an C++ shared library statically

2013-09-22 Thread Xiangrong Fang
Have you tried to pass options to the linker using -k? That worked, thanks. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] bridging an C++ shared library statically

2013-09-21 Thread Xiangrong Fang
Hi All, I need to use a C++ so file in FreePascal. I have written a C wrapper for it, which successfully connected to Pascal. Now my question is, can I use the $linklib directive to link the C-Wrapper STATICALLY, which in-turn use the shared so file? I tried to do this but it complained a

Re: [fpc-pascal] bridging an C++ shared library statically

2013-09-21 Thread Xiangrong Fang
, Xiangrong Fang wrote: Hi All, I need to use a C++ so file in FreePascal. I have written a C wrapper for it, which successfully connected to Pascal. Now my question is, can I use the $linklib directive to link the C-Wrapper STATICALLY, which in-turn use the shared so file? I tried to do

Re: [fpc-pascal] bridging an C++ shared library statically

2013-09-21 Thread Xiangrong Fang
1) Did you give the correct name ? 2) Is the current dir in the linker search path ? AFAIK the current dir is by default not in the linker search path. I am sure the name is correct. No matter I supply the linker path (-Fl.) or not, it does not work (i.e. ld reported cannot find

[fpc-pascal] Bug in $linklib?

2013-09-21 Thread Xiangrong Fang
Hi All, I use $linklib to link my fpc program with a C++ so file. I found that the $linklib directive does NOT conform with ld specification. This is what I did and found: PURPOSE I want to link to a C library that does NOT start with lib prefix. The library's name is thostmduserapi.so

[fpc-pascal] Error linking with C code

2013-09-18 Thread Xiangrong Fang
Hi All, I am writing pascal wrapper for a C library called CTP, which is used in future trading. My project is here: https://github.com/xrfang/CTPas Compiling the interface file along is successful. While linking, fpc complains: ./thostmduserapi.so, needed by ./libthost.so, not found (try

Re: [fpc-pascal] Error linking with C code

2013-09-18 Thread Xiangrong Fang
where is thostmduserapi.so ? Michael. This file is under libthost folder, I copied it to pasintf folder then use fpc to compile demo.pas. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] Error linking with C code

2013-09-18 Thread Xiangrong Fang
I think you should try to pass the name of the folder where libthost is to the linker. -FL/path/to/libthost Michael. This does not work, same error message. I also tried to copy libthost.so to current dir, but leave thostmduserapi.so in ../libthost, same result. Regards, Xiangrong

Re: [fpc-pascal] Object constructor

2013-09-17 Thread Xiangrong Fang
My question is, since the programmer is responsible for explicitly call object constructors, then why do we need constructors at all? In another word, what's the difference between an object constructor and an object method? Using the constructor tells the compiler that it should allocate

[fpc-pascal] Object constructor

2013-09-16 Thread Xiangrong Fang
Hi All, Could anyone please explain this: 5.4 Constructors and destructors http://www.freepascal.org/docs-html/ref/ref.html#QQ2-64-77 As can be seen in the syntax diagram for an object declaration, Free Pascal supports constructors and destructors. The programmer is responsible for calling the

Re: [fpc-pascal] returning a generic object?

2013-09-12 Thread Xiangrong Fang
TSelfType worked like a charm. Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] IFPObserved

2013-09-11 Thread Xiangrong Fang
Hi All, Where can I find detailed documentation on IFPObserved? This page only defines the interface but not telling about the purpose of this interface: http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html My questions are: - what is this interface for? - any example on when and

Re: [fpc-pascal] IFPObserved

2013-09-11 Thread Xiangrong Fang
is not compatible with Delphi? 5) I am very interested in your CD-Cover designer. please send me the article and code. Thank you! 2013/9/11 Michael Van Canneyt mich...@freepascal.org On Wed, 11 Sep 2013, Xiangrong Fang wrote: Hi All, Where can I find detailed documentation on IFPObserved

Re: [fpc-pascal] IFPObserved

2013-09-11 Thread Xiangrong Fang
Hi Michael, 3) What are Live Binding? What's the difference between IFPObserved and the component events like OnCreate, OnShow, OnClick...? See IFPObserved as a general event mechanism. The main difference is that a component can have only 1 OnCreate handler. whereas, in theory, an

[fpc-pascal] Re: weird compile error message

2013-09-11 Thread Xiangrong Fang
/x86_64-linux -Fu. -FUlib/x86_64-linux/ -l project1.lpr However if I remove these -F, it is OK: fpc -MObjFPC -Scghi -O1 -g -gl -vewnhi -l project1.lpr Is this a bug in the compiler? I attached the complete source (3 files) so that you can test it. Thanks a lot! 2013/9/11 Xiangrong Fang xrf

[fpc-pascal] TObject and @TObject (are objects pointers?)

2013-09-11 Thread Xiangrong Fang
Hi, I am writing a Tree class which have the following skeleton: generic TTreeT = class private FItems: TList; public ... end; The FItems variable is used to store Children of current node. My question is: Shall I store TTree in FItems or @TTree? My understanding is: If a variable obj

Re: [fpc-pascal] Re: weird compile error message

2013-09-11 Thread Xiangrong Fang
Hi, Missing -T is not the problem, the problem is undefined reference, which caused fatal error. I filed a bug report: http://bugs.freepascal.org/view.php?id=25001 I am pretty sure this is a bug, becuase while I continue to add code to my TTree class, this problem is gone! In another word, it

Re: [fpc-pascal] Re: weird compile error message

2013-09-11 Thread Xiangrong Fang
Hi Sven, Additional note: The PTree = ^TTree in front of the TTree is wrong and only supported by pre-2.7.1 FPC by accident. The correct code would be: I removed PTree yesterday and this problem is gone. I now understand that it is not necessary to define PTree as TTree is a pointer anyway.

Re: [fpc-pascal] Re: weird compile error message

2013-09-11 Thread Xiangrong Fang
Hi Sven, I have downloaded fpcbuild.zip and did 'NOGDB=1 make build', as it tell me cannot find libgdb.a... Now my question is how can I install the binaries so that it does NOT interfere with my current 2.6.2 build? Thanks! ___ fpc-pascal maillist -

[fpc-pascal] returning a generic object?

2013-09-11 Thread Xiangrong Fang
Hi All, I have this generic class: type generic TTreeT = class private FItems: TList; ... ... public Data: T; ... ... function FirstChild: TTree; ... ... end; function TTree.FirstChild: TTree; begin if FItems.Count = 0 then Exit(nil); Exit(TTree(FItems[0]));

[fpc-pascal] procedure that accept generic types?

2013-09-04 Thread Xiangrong Fang
Hi There, I try to write a procedure with generic parameters, but failed: type generic TArrayT = array of T; procedure ProcessArray(arr: TArrayT); begin end; The compiler said Generics without specialization cannot be used... But if I specialize the parameter then this procedure is

Re: [fpc-pascal] procedure that accept generic types?

2013-09-04 Thread Xiangrong Fang
this: var proc_ints: specialize ProcessArrayLongInt; begin proc_ints(someintarray); end; use it without explicit specialize is best, however. 2013/9/4 Sven Barth pascaldra...@googlemail.com Am 04.09.2013 08:18, schrieb Xiangrong Fang: Hi There, I try to write a procedure with generic

Re: [fpc-pascal] procedure that accept generic types?

2013-09-04 Thread Xiangrong Fang
in delphi mode?btw, my last experience with Delphi is 6 or 7, there was no generics yet. Thanks 2013/9/4 Sven Barth pascaldra...@googlemail.com Am 04.09.2013 09:13, schrieb Xiangrong Fang: Thanks. This is sort-of too verbose when use. I have no comments about how to define

[fpc-pascal] Runtime error 217 on array of Variant

2013-09-04 Thread Xiangrong Fang
Hi there, I would like to use TVarRec as Variants, after some googling I found this: http://stackoverflow.com/questions/3733640/how-to-convert-between-tvarrec-and-variant However, it generated Runtime error 217. My original code (runs OK) is: 1 program test; 2 {$mode objfpc}{$H+} 3

[fpc-pascal] Re: Runtime error 217 on array of Variant

2013-09-04 Thread Xiangrong Fang
I found the problem myself. You have to add uses Variants to eliminate the problem. So now my questions are: 1) why the Variants unit is required? What does it do? 2) is there any performance penalty using Variant than TVarRec? Thanks! 2013/9/5 Xiangrong Fang xrf...@gmail.com Hi

Re: [fpc-pascal] Understanding virtual methods

2013-08-20 Thread Xiangrong Fang
On 20/08/2013 02:44, Xiangrong Fang wrote: Hi All, I am reading this document: http://www.freepascal.org/docs-html/ref/refsu29.html and doing an experiment with the following code: program project1; {$mode objfpc}{$H+} type TBase = class constructor Create; virtual; end

Re: [fpc-pascal] Understanding virtual methods

2013-08-20 Thread Xiangrong Fang
is an instantiated class. You are aware that the link mentioned by Xiangrong Fang points to a part of the manual about Turbo Pascal style objects which are different in a different sense to Delphi style objects/classes? Yes, but as he posts a question in a FPC list I imagine he is looking

[fpc-pascal] Understanding virtual methods

2013-08-19 Thread Xiangrong Fang
Hi All, I am reading this document: http://www.freepascal.org/docs-html/ref/refsu29.html and doing an experiment with the following code: program project1; {$mode objfpc}{$H+} type TBase = class constructor Create; virtual; end; TDerived = class(TBase) constructor Create;

Re: [fpc-pascal] Understanding virtual methods

2013-08-19 Thread Xiangrong Fang
classes, is there any difference here? Shannon 2013/8/20 Flávio Etrusco flavio.etru...@gmail.com On Mon, Aug 19, 2013 at 10:44 PM, Xiangrong Fang xrf...@gmail.com wrote: Hi All, I am reading this document: http://www.freepascal.org/docs-html/ref/refsu29.html and doing an experiment

[fpc-pascal] Tree data structure

2013-06-01 Thread Xiangrong Fang
Hello, Is there any built-in general Tree data structure in FPC/Lazarus library? General means: 1) it is a generic class or its node is a pointer which is suitable for general use 2) it is NOT balanced tree or binary tree, but just like a file system tree. In another word, I am looking for a

[fpc-pascal] How to detect connection status of a socket

2013-04-22 Thread Xiangrong Fang
Hi All, I am writing a redis client in fpc and found that even when the connection is closed by server (via redis CLIENT KILL), send and receive can still be done without error. i.e.: - fpsend returns the number of bytes sent - fprecv returns 0 (but NOT -1, which indicate a detectable error,

Re: [fpc-pascal] How to detect connection status of a socket

2013-04-22 Thread Xiangrong Fang
2013/4/22 Marco van de Voort mar...@stack.nl In our previous episode, Xiangrong Fang said: I am writing a redis client in fpc and found that even when the connection is closed by server (via redis CLIENT KILL), I don't know the redis protocol is, but CLIENT KILL sounds like redis

Re: [fpc-pascal] How to detect connection status of a socket

2013-04-22 Thread Xiangrong Fang
2013/4/22 Michael Schnell mschn...@lumino.de As long as no event happens to one of the sites, the socket is esteemed connected by this site. This does not mean that the other site thinks the same OK, as connection status is a complex issue, I try to put it in another way: 1) fpsend() just

Re: [fpc-pascal] string memory management

2013-04-19 Thread Xiangrong Fang
2013/4/19 Michael Van Canneyt mich...@freepascal.org 1. I don't know whether I have to MANUALLY free memory for these strings to prevent leak? Yes, if you work like this, you must do all that. You must free all pointers in the list, and the strings they point to. But why not use

[fpc-pascal] string memory management

2013-04-18 Thread Xiangrong Fang
Hi All, I'm studying how pascal manages strings. I wrote a simple test program: program stringtest; {$mode objfpc}{$H+} uses Classes, sysutils; function test: PString; var s : string; begin New(Result); Result^ := FloatToStr(Random); // s := FloatToStr(Random); // Result := @s; end; var

Re: [fpc-pascal] socket timeout

2013-04-17 Thread Xiangrong Fang
AM, Xiangrong Fang wrote: How can I set the connection and read/write timeout when using socket in free pascal? I seem to remember that synapse can do this. Only in svn and it does it this way if FConnectionTimeout 0 then begin // connect in non-blocking mode b := NonBlockMode

Re: [fpc-pascal] socket timeout

2013-04-17 Thread Xiangrong Fang
mode (which I don't use). For MSG_DONTWAIT as far I know you have to change to the nonblocking mode. 2013/4/16 Luca Olivetti l...@ventoso.org Al 16/04/13 12:20, En/na Michael Schnell ha escrit: On 04/16/2013 11:26 AM, Xiangrong Fang wrote: How can I set the connection

[fpc-pascal] why connect is deprecated

2013-04-16 Thread Xiangrong Fang
Hi All, I am trying to write a tcp client (redis) in free pascal, and found this function marked as deprecated: Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:text):Boolean; deprecated; My question is, why it is deprecated, or, what is the replacement for this

Re: [fpc-pascal] why connect is deprecated

2013-04-16 Thread Xiangrong Fang
Yes, I read the source code and found that fpconnect + socktotext = connect, but just don't know why combining them together is a bad idea :-) thanks 2013/4/16 Victor Campillo victor.campi...@gmail.com On 16/04/13 11:12, Xiangrong Fang wrote: Hi All, I am trying to write a tcp client

Re: [fpc-pascal] why connect is deprecated

2013-04-16 Thread Xiangrong Fang
using the socket like read/write file is very convenient. This is the first time I use fpc to write socket program, it is much easier than I used Indy or ICS in Delphi several years ago. I hope to modernize or make it more stable, instead of deprecate it. Of course deprecate Connect and use

[fpc-pascal] String type compatibility

2013-04-03 Thread Xiangrong Fang
Hi, In the following program: program worksheet; {$mode objfpc}{$H+} type TWorksheet = packed object private FProp: string[5]; //FProp: Integer; public property Prop: ShortString read FProp; //property Prop: Integer read FProp; end; begin end. I got an error while

Re: [fpc-pascal] String type compatibility

2013-04-03 Thread Xiangrong Fang
2013/4/3 Marco van de Voort mar...@stack.nl Shortstring, is an alias for shortstring[255] the maximum size. Use getters and setters if you want to make this work. Thanks, however, I am just defining getter. So, to make this work, I need to define things like: type MyProp = string[5];

Re: [fpc-pascal] Re: String type compatibility

2013-04-03 Thread Xiangrong Fang
It's because in Pascal you need to declare types first. But why array[0..10] of Integer, or string[255] are not types? Remember that you can use open array in function params anyway. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] Feature proposal: function-based assignment operators

2013-03-29 Thread Xiangrong Fang
No, there is no difference, because even if we would implement support for function based operators we would not implement any default ones or only provide them with an additional unit. So you either need to implement them yourself or use an additional unit anyway. I mean, with the proposed

Re: [fpc-pascal] Feature proposal: function-based assignment operators

2013-03-28 Thread Xiangrong Fang
2013/3/29 Sven Barth pascaldra...@googlemail.com There was already a discussion some time ago whether we should allow operators like or= and such as well and the result was simple: no. I consider this the same here. You can achieve a similar effect through type helpers in 2.7.1 though:

Re: [fpc-pascal] position of External: SIGFPE

2013-03-25 Thread Xiangrong Fang
We are now several decades later, but for compatibility reasons the FPU on the x86 processors still uses the same logic. It is possible to get the exception at the place where it happened by inserting fwait instructions after every fpu operation. Those tell the cpu to stop executing until the

Re: [fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

2013-03-23 Thread Xiangrong Fang
if (Rank = 0) or (Anchor Key) then Rank += 1; -- error here Result := nil; end; It seems that the += operator is not supported anymore?? Is there any switches in the new 2.7.1? 2013/3/23 Sven Barth pascaldra...@googlemail.com On 23.03.2013 03:35, Xiangrong Fang wrote: Hi Sven, My unite

Re: [fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

2013-03-23 Thread Xiangrong Fang
types: got TTreap$2$crc94C56373 expected TRoller demo2.lpr(98) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted 2013/3/24 Sven Barth pascaldra...@googlemail.com On 23.03.2013 14:51, Xiangrong Fang wrote: I got this error now: treap.pas(311,48) Error: Illegal

Re: [fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

2013-03-22 Thread Xiangrong Fang
2013/3/22 Sven Barth pascaldra...@googlemail.com The problem is gone, because PNode is not a generic class, but only a record. However, the following errors are generated: 2.6.x does not support nested types in generics. Generic fixes and improvements are only found in 2.7.1 as most of

Re: [fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

2013-03-22 Thread Xiangrong Fang
I didn't see a DEB package for 2.7.1. I am currently using 2.6.0. Can I compile 2.7.1 from source with 2.6.0? 2013/3/22 Sven Barth pascaldra...@googlemail.com Am 22.03.2013 08:13, schrieb Xiangrong Fang: 2013/3/22 Sven Barth pascaldra...@googlemail.com The problem is gone, because PNode

Re: [fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

2013-03-22 Thread Xiangrong Fang
Hi Sven, My unite uses contnrs unit, how can I instruct the compiler to use the contnrs unit (also the Classes and sysutils units) of v2.7.1? I have already built 2.7.1 and now try to compile my program in the fpc source dir as you told. Thanks 2013/3/22 Xiangrong Fang xrf...@gmail.com I

Re: [fpc-pascal] How To write an enumerator for trees

2013-03-21 Thread Xiangrong Fang
On Thu, 21 Mar 2013 11:11:49 +0800 Xiangrong Fang xrf...@gmail.com wrote: Hi, I would like to add enumerator support for my TTreap implementation ( https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas). The tree nodes are defined as: PNode = ^TNode; TNode

Re: [fpc-pascal] TFPDataHashTable: how to iterate?

2013-03-21 Thread Xiangrong Fang
I was told that it will be possible in 2.7... If you like, take a look at my TTreap class, which can be used as a hash table: https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas 2013/3/21 S. Fisher expandaf...@yahoo.com Is there any way to iterate over a TFPDataHashTable ?

[fpc-pascal] enumerate generic trees

2013-03-21 Thread Xiangrong Fang
Hi There, I encountered a problem writing enumerator for my generic tree. The enumerator class looks like this: TTreapEnumerator = class FStack: TStack; FCurrent: TTreap.PNode; public constructor Create(ANode: TTreap.PNode); destructor Destroy; override; function

[fpc-pascal] Use generic class as parameter (was: how to write enumerator for trees)

2013-03-21 Thread Xiangrong Fang
Hi, I try to do exactly the same as show here: QUOTE: http://svn.freepascal.org/svn/fpc/trunk/packages/fcl-stl/src/gvector.pp generic TVectorT = class ... ... type TVectorEnumerator = class private FVector: TVector; FPosition: SizeUInt; FFirstDone: Boolean;

[fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

2013-03-21 Thread Xiangrong Fang
MKey: Char; Max: Integer; constructor Create; override; end; I think there is no need to define TTreapEnumerator in THistogram again, right? Xiangrong 2013/3/22 Xiangrong Fang xrf...@gmail.com Hi, I try to do exactly the same as show here: QUOTE: http://svn.freepascal.org

[fpc-pascal] How To write an enumerator for trees

2013-03-20 Thread Xiangrong Fang
Hi, I would like to add enumerator support for my TTreap implementation ( https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas). The tree nodes are defined as: PNode = ^TNode; TNode = record Count: Cardinal; Key: TKey; Value: TValue;

Re: [fpc-pascal] a proposal about with syntax

2013-03-18 Thread Xiangrong Fang
Xiangrong Fang xrf...@gmail.com: OK, I see. However I feel = a very un-pascal thing, remind me of PHP. :-) I guess as would also complicate the parser? As already written by others: as is one of the worst tokens you can choose for this, as it is perfectly legal to do a typecast in an expression

Re: [fpc-pascal] a proposal about with syntax

2013-03-18 Thread Xiangrong Fang
2013/3/18 Marco van de Voort mar...@stack.nl In our previous episode, Xiangrong Fang said: Alternatively, how about just use SPACE to separate the token? i.e.: with SomeObject o1, SomeOtherObject o2 do That's perfectly fine for C. But this isn't C. What's wrong here? In pascal, we

Re: [fpc-pascal] a proposal about with syntax

2013-03-18 Thread Xiangrong Fang
2013/3/18 Marco van de Voort mar...@stack.nl In our previous episode, Xiangrong Fang said: In our previous episode, Xiangrong Fang said: Alternatively, how about just use SPACE to separate the token? i.e.: with SomeObject o1, SomeOtherObject o2 do That's perfectly fine

Re: [fpc-pascal] Re: a proposal about with syntax

2013-03-18 Thread Xiangrong Fang
2013/3/18 leledumbo leledumbo_c...@yahoo.co.id I cannot recall if there is already a notion of alias in free pascal, if not then we just introduce this idea within the scope of with expression. Let me give you one then: procedure p; [public, alias: 'my_p']; Is it related to COM or DLL

Re: [fpc-pascal] a proposal about with syntax

2013-03-17 Thread Xiangrong Fang
The AS syntax bites already existing syntax. May I know what's the existing syntax? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] a proposal about with syntax

2013-03-17 Thread Xiangrong Fang
I am sorry I didn't follow this thread although I am the OP :-). If I understand correct, I would suggest NOT introduce the absolute keyword, instead, make it ALWAYS absolute. i.e.: with a = SomeObject, b = SomeRecord do begin ... ... end; Both a and b are reference to the object or record,

Re: [fpc-pascal] a proposal about with syntax

2013-03-17 Thread Xiangrong Fang
OK, I see. However I feel = a very un-pascal thing, remind me of PHP. :-) I guess as would also complicate the parser? 2013/3/18 Paul Ishenin paul.ishe...@gmail.com 18.03.13, 9:27, Xiangrong Fang пишет: I am sorry I didn't follow this thread although I am the OP :-). If I understand

[fpc-pascal] a proposal about with syntax

2013-03-16 Thread Xiangrong Fang
Suppose I have the following class: type TMyClass = class public property Caption: string read FCaption write FCaption; property Items[Index: Integer]: string read GetItem write SetItem; default; function Count: Integer; end; I would like to do this: with MyClassInstance as

Re: [fpc-pascal] a proposal about with syntax

2013-03-16 Thread Xiangrong Fang
16.03.2013 07:14 schrieb Xiangrong Fang xrf...@gmail.com: Suppose I have the following class: type TMyClass = class public property Caption: string read FCaption write FCaption; property Items[Index: Integer]: string read GetItem write SetItem; default; function Count: Integer

Re: [fpc-pascal] a proposal about with syntax

2013-03-16 Thread Xiangrong Fang
Sorry, the email was interrupted, but sent by the phone in background... So the decision of this feature is that it is not worth to add, right? Thanks. 2013/3/16 Xiangrong Fang xrf...@gmail.com In my example, you can use Items[], but in my real project it is a record with 发送自魅族MX

Re: [fpc-pascal] a proposal about with syntax

2013-03-16 Thread Xiangrong Fang
shiruba shir...@galapagossoftware.com's example is better than mine, and was exactly the reason I posted this suggestion. I don't think a class helper is worth for this stuff, if I need to write a helper I would rather do this: longobj := BigLongThingIDontWantToWriteOutEverySingleTime; With

Re: [fpc-pascal] a proposal about with syntax

2013-03-16 Thread Xiangrong Fang
I don't know what's make it complex if there are 2 or more subject in the with? Context. A conflict case the two object were of the same class. Are you saying this case: with MyClassInstance1 as m, MyClassInstance2 do begin m.Property1 := 123; Property2 := 456; end; Here you don't

Re: [fpc-pascal] about reference-counted variables

2013-03-14 Thread Xiangrong Fang
Also widestrings are not refcounted on the pascal level, but managed. What's the implication of the difference between refcounted vs. managed? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] catch segfaults

2013-03-14 Thread Xiangrong Fang
Thanks for the explanation. Now I see why my program some time crashed at gtk2*.inc... 2013/3/14 Martin laza...@mfriebe.de On 14/03/2013 09:47, Jonas Maebe wrote: On 14 Mar 2013, at 01:48, Xiangrong Fang wrote: The document said it is deprecated? Also, I want this to be cross platform

[fpc-pascal] two questions about dynamic array

2013-03-13 Thread Xiangrong Fang
Hi All, I have two simple questions: 1) As far as I know class variables in FPC are automatic initialize to the NULL value (e.g. 0 or or whatever), does that include dynamic arrays? e.g. TMyClass = class myarray: array[0..100] of Integer; end; will myarray be initialized to nil? 2)

[fpc-pascal] Re: two questions about dynamic array

2013-03-13 Thread Xiangrong Fang
Sorry the array should be dynamic, without [0..100]. 2013/3/12 Xiangrong Fang xrf...@gmail.com Hi All, I have two simple questions: 1) As far as I know class variables in FPC are automatic initialize to the NULL value (e.g. 0 or or whatever), does that include dynamic arrays? e.g

[fpc-pascal] Selective Class Helper

2013-03-13 Thread Xiangrong Fang
Hi There, Is it possible for class helpers to be selective? i.e. attach to a specific object of that class, but not every instance? This would be useful for behavior injection. Thanks ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] Re: two questions about dynamic array

2013-03-13 Thread Xiangrong Fang
Yes, in that case it will be Nil (Note: in the static case the elements of the array would be 0). So, it is even OK to use SetLength() on static arrays? interesting. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] two questions about dynamic array

2013-03-13 Thread Xiangrong Fang
2013/3/13 Sven Barth pascaldra...@googlemail.com Am 13.03.2013 10:08 schrieb Xiangrong Fang xrf...@gmail.com: 2) After SetLength(myarray, 0), is myarray nil or pointing to some invalid address? It will be Nil. An equivalent alternative would be: MyArray := Nil; Sorry, I didn't see

[fpc-pascal] catch segfaults

2013-03-13 Thread Xiangrong Fang
Is it possible to use try...except to catch SIGSEGV? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] catch segfaults

2013-03-13 Thread Xiangrong Fang
The document said it is deprecated? Also, I want this to be cross platform, not for unix only. The use case is: try buf := GetMemory(1024); size := 10240; stream.Read(buf^, size); except ?? end; 2013/3/14 Ewald ew...@yellowcouch.org Once upon a time, Xiangrong Fang said

<    1   2   3   >