Re: [fpc-pascal] Memory leak or object destruction?
On Wed, 2 Feb 2011 21:09:42 -0800, Andrew Hall wrote: Interfaces support reference counting. Only COM interfaces, but they are currently the default anyway. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: New multicast event implementation
Have you used List, Dictionary, or IEnumerable in C# much? How about EventHandler? They are pretty useful. Even in Delphi, TList, TObjectList, and TCompare are more than handy IMO. No longer do I have to write "TMyObject(FList[I])" all over the place. When using "if FList.IndexOf(Pointer(FInstance)) > 1" not only do you need a typecast again, but you lose the ability to write or build in TCompare, for example to consider objects equal by comparing a specific field. Anyhow, I didn't mean this discussion to be about the merits of generics in programming. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] dynamic array and new/dispose
On 02 Feb 2011, at 14:28, Jonas Maebe wrote: On 02 Feb 2011, at 14:10, Amit Bueno wrote: Have you got the prof.rar? No. I've just looked at the posts held for moderation and your mail is over 5MB. That is way too large to send to a mailing list. I just saw the new message in the moderation queue, but it's still over 600KB (email makes files about 30% bigger because of the inefficient encoding), which is too big for a mailing list (50-100KB is the maximum I'll let through, <=50KB is let through automatically). However, it's also available for download now: *** Attached is the shrinked prof.rar file (481kb). You can download it as well from: http://bueno.co.il/files/prof.rar --- Amit *** Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: New multicast event implementation
Am 02.02.2011 15:40, schrieb Anthony Walter: By the way, does Free Pascal generic support generic constraints yet? Also, this format seems more natural to me: They aren't implemented currently, but I hope they will at some time. TCollection = class property Count: Integer; property Items[Index: Integer]: T; end; TStatusPanels = class(TCollection); rather than ... generic TCollection = class // no constrain ability property Count: Integer; property Items[Index: Integer]: T; end; TStatusPanels = specialize TCollection; When using FPC 2.5.1 you can use the Delphi compatible syntax in mode Delphi (not supported in mode ObjFPC). When constraints are implemented they should work in both modes. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] dynamic array and new/dispose
On 02 Feb 2011, at 17:26, Amit Bueno wrote: > Seems that I found a workaround. > When calling the NewSubChunk in the following syntax: > SubChunks[NewSubChunk]^.read(fl); /// raise an exception. > > While > MyIndex := NewSubChunk; > SubChunks[MyIndex]^.read(fl); /// raise an exception. > > Doesn't raise any excetion…. > Maybe the experts could say why, I don't know why… The reason is that SubChunks (a dynamic array) can be nil before NewSubChunk() (a function that allocates 2 extra elements for that array) is called. So if the compiler first loads SubChuncks (=nil) in a register, then calls NewSubChunk, and then indexes this nil pointer using that function result, you will get at an access violation. The original code is wrong because Pascal does not define a particular order in which such expressions have to be evaluated by the compiler. In general, calling functions with side effects inside expressions that can be affected by those side effects is very bad practice (and dangerous, as you've noticed). The fact that it doesn't crash in the Delphi version that you tested is pure coincidence, and it may very well crash is older or newer versions. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Correct use of var in function calls?
I am a bit confused over the way to specify parameters to function calls as var or not I have the following constructs: type TByteArr = array of byte; I have a buffer class that receives data from a serial port and now I want to extract data from this buffer to various types of variables in the main application class. So far I have managed all the simple variable types successfully, the only remaining part is the handling of a body of varying length of data. In my main class the data will wind up in a dynamic array of bytes (TByteArr as above). In the main class: function .GetData(Dest:TByteArr): boolean; <== calculate length of data in bytes as Len SetLength(Dest, Len); if not FRxBuf.Read(Dest) then exit; In the buffer class I have a number of overloaded Read functions: function Read(Dest: Pointer; Count: Cardinal): Cardinal; overload; function Read(var Data: TByteArr): boolean; overload; ... and 5 more implemented as: function TSSCommBuf.Read(var Data: TByteArr): boolean; // <== ??? begin Result := Read(@Data, SizeOf(Data)) = SizeOf(Data); end; function TSSCommBuf.Read(Dest: Pointer; Count: Cardinal): Cardinal; var num: Cardinal; Src: Pointer; begin num := FWriteIndex - FReadIndex; //Remaining data bytes in buffer if num >= Count then num := Count; if num > 0 then begin Src := @FBuf[FReadIndex]; // FBuf is a TByteArr sized on demand Move(Src^, Dest^, num); FReadIndex := FReadIndex + num; end; Result := num; end; My question concerns the lines marked with <== ??? Do I use var in the declaration or not? As you can see the similar functions are differently written now. In Delphi I think that if an object or a dynamic array is passed as argument it does not need the var declaration, but I am not sure. I want to treat the array as a variable because it is the return container for the data. Bo Berglund ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Installing fpc 2.5.1 from svn
Hi ! How can i download and install fpc 2.5.1 from svn in my ubuntu 10.04 x86_64 ? Thanks ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal