[fpc-pascal]Classes and copying
Hi all, With respect to classes (and perhaps also objects), how do you copy the contents of a class in memory (an object) to another? ie: var a: TClass; b: TClass; begin a := TClass.init; b := a; //This only copies the pointer and doesn't work ?? end. cheers James ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Classes and copying
On Wed, 12 Feb 2003, James Mills wrote: > Hi all, > > With respect to classes (and perhaps also objects), how do you copy the > contents of a class in memory (an object) to another? > > ie: > > var > a: TClass; >b: TClass; > > begin > a := TClass.init; > b := a; //This only copies the pointer and doesn't work ?? > end. > This indeed only copies the pointer. if you want to do more than that, then you need to implement this yourself. TPersistent implements the 'Assign' method for this. You can create a descendent from TPersistent, override the Assign method, and then copy fields as necessary in the new Assign method. Michael. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
RE: [fpc-pascal]Classes and copying
> This indeed only copies the pointer. if you want to do more > than that, then you need to implement this yourself. > > TPersistent implements the 'Assign' method for this. You can > create a descendent from TPersistent, override the Assign > method, and then copy fields as necessary in the new Assign method. And also that, whilst this sounds tedious, you could (in Delphi mode only I guess) use RTTI to automate some of it. There is at least one component (have a look for zproplst.zip on Torry.net, or if you have the Delphi source there is a hidden TPropList class) that goes through the published members and gets all their names and types. You can then use the routines in the unit Typinfo (might be part of fcl I guess, should be in the Delphi compatible part of the RTL at least though) to retrieve and set their values. Caveat, you *must* declare all members that you with to get at as being Published, it only really works well for properties and your classes should descend from Tpersistent. Having said all that, it works really well in Delphi, and I assume Delphi mode (S2 or Sd). Does the TP or the ObjFPC mode support RTTI and the Typinfo unit? Noting also that whilst C++ has a nice syntax for this (the 'copy' constructor/operator overloading dodge) all it really does is the same as Assign (mostly) but just in a more convoluted way. Matt ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Classes/Objects/Pointers / Pointer Help
On woensdag, feb 12, 2003, at 04:17 Europe/Brussels, Anton Tichawa wrote: i long to be a member of the free pascal development team. comments are welcome. are there any rites involved, such as programming a 4d-visualization of the fourier transform or creating an aboriginal version of the VCL? The only "requirement" is that you supply several patches to fix bugs in the compiler and/or rtl/packages/fcl/... When we become bored committing all your patches, you get cvs write access so you can commit them yourself and you're "part of the team" :) Jonas ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Classes and copying
Matt D. Emson schrieb: Having said all that, it works really well in Delphi, and I assume Delphi mode (S2 or Sd). Does the TP or the ObjFPC mode support RTTI and the Typinfo unit? Yes, what you have described should work well in FPC, too. - Sebastian ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
RE: [fpc-pascal]Classes/Objects/Pointers / Pointer Help
ok, so for the appropriate o/s we repeat 1 just scan the local disks for eg the ppc386.exes, fp.exes, ppc.cfgs, base*,zips, ide*.zips or whatever are appropriate for the o/s & o/p to screen what versions etc the user has on the system 2 then look in ppc.cfg & check whether the references there eg to paths & files are valid 3 generate n programs & compile them, o/p any compile errors 4 run tests (eg those in the cvs ??? or the ones in the program we are discussing? or both) & o/p results/errors 5 if tests are in loop stop the pograms & o/p error message until (timeout or ctrl/c or ???); Sounds as if 3 & 4 are the difficult bits... Regards John -Original Message- From: Anton Tichawa [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 04:18 To: [EMAIL PROTECTED] Subject: Re: [fpc-pascal]Classes/Objects/Pointers / Pointer Help Hello, John! > can also contribute eg a (non OO) FP test unit? if you like. Any ideas > about how to define the 'features' to be tested? Regards John *** procedure define; begin lock; // (?) brainstorm; .. *** well, my first contribution to a brainstorming of features to be tested is - * DETERMINE SYSTEM STATUS ..: the test program should determine and evaluate the status of installed compilers / ides on the given system, without write operations e. g. to the mass storage media. things such as missing, misplaced, misspelled, .., or ambiguos configuration, e. g. in the file fpc.cfg, should be mentioned on the screen. upon user intervention - and also timeout is a user intervention - the status should be first saved and then be overloaded with a new one that seems appropriate to both user and tester. but that's not really important at the moment. the important thing is that the saved stati - those that didn't seem appropriate at the moment - are the most valuable thing of free pascal from a certain point of view. this is the output of the tester program, the bug list, and will help answer any question that may come in the future. i'm talking about, well, excuse my poor english here, fehler (d) = errrors (e) (?), because in every such "thing" is one bit of truth that will surely be reconsidered as free pascal development continues. no bug must be lost, or so .. uh. anton tichawa. -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Classes/Objects/Pointers / Pointer Help
Hello! > 3 generate n programs & compile them, o/p any compile errors > 4 run tests (eg those in the cvs ??? or the ones in the program we are > Sounds as if 3 & 4 are the difficult bits... But I actually do step 3 on my PC, under linux. I tried the same before under a popular operating system, but though working several hours, I did not manage to start one application from within another one. There was a function that worked, but it was called "deprecated" or so. Step 3 would be to generate pascal sources. This generation has it's root in the definition of the Pascal Language and would check every feature to a certain degree, using "equivalence classes". Step 3 includes checking if the compiler produces errors where it should produce an error, and if it compiles where it should compile. The actual output would be a bug list. Only those cases where Step 3 is bug-free, would then be executed .. Anton. "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]SysUtils.FileExists bug under Go32v2
Hi, I think I've found a bug on the FileExists function (sysutils) under Go32v2, when I want to check if a directory exists. FileExists( 'c:\winnt' ) will return False when compiled for Go32 but true for Win32. I guess that the Win32 version is doing rigth, since a directory is part of the file system. I've checked a recent CVS copy of the sources and I found this [go32v2/sysutls.pp] Function FileExists (Const FileName : String) : Boolean; var Handle: longint; begin //!! This can be done quicker, need to find out how Result := (OpenFile(FileName, Handle, ofRead, faOpen) = 0); if Handle <> 0 then FileClose(Handle); end; this could be changed for example to: Function FileExists (Const filename :String) :Boolean; begin //FileGetAttrib will return -1 if the file was not found //but I don't know if it will return -1 if the file exists but it's open result := boolean( FileGetAttr( filename ) XOR -1 ); end; hope this helps, Ivan ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]SysUtils.FileExists bug under Go32v2
Hello, Ivan! > Function FileExists (Const filename :String) :Boolean; > begin >//FileGetAttrib will return -1 if the file was not found >//but I don't know if it will return -1 if the file exists but it's open >result := boolean( FileGetAttr( filename ) XOR -1 ); > end; I'll have a look at that .. Anton Tichawa. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]SysUtils.FileExists bug under Go32v2
Hello! The following should work under 32-bit windows-compatible os's: *** Function FileExists (Const filename :String) :Boolean; var S: TSEARCHREC; begin R := FindFirst(Filename, faAnyFile, S); Result := R = 0; if R = 0 then FindClose(S); end; *** Status: Untested. Caution: The circumstances under which FindClose should be called are not clearly formulated by the original manufacturer. My procedure is just a proposal. I saw a system hanging several seconds or maybe even crashing when I called, or missed to call, FindClose. The fact that the condition R = 0 has to be tested twice, shows the poor quality of the API. BTW: How and where can I obtain the original microsoft 32-bit windows API help files, and what names do they have? I thing *.chm or so? HTH Anton Tichawa. -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]ExtractFileDir ?
According to the docs http://www.freepascal.org/docs-html/units/node23.html#SECTION0023660 00 "ExtractFileDir returns only the directory part of FileName, not including a driveletter." But it does return the driveletter, so either the docs are mistaken or the RTL. If the docs are right here there is a function that will return only the dir, removing any drive letter. ie: c:\testdir\test\file.ext => \testdir\test c:\testdir\ => \testdir c:testdir\ => testdir \testdir\test.exe => \testdir [objpas\fina.inc] function ExtractFileDir(const FileName: string): string; var i,j: longint; begin if FileName[2]=':' then j:=3 else j:=1; I := Length(FileName); while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I); if (I > j) and (FileName[I] in ['\', '/']) and not (FileName[I - 1] in ['/', '\', ':']) then Dec(I); Result := Copy(FileName, j, I-j+1); end; HTH, ivan ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]ExtractFileDir ?
According to the docs http://www.freepascal.org/docs-html/units/node23.html#SECTION0023660 00 "ExtractFileDir returns only the directory part of FileName, not including a driveletter." But it does return the driveletter, so either the docs are mistaken or the RTL. If the docs are right here there is a function that will return only the dir, removing any drive letter. ie: c:\testdir\test\file.ext => \testdir\test c:\testdir\ => \testdir c:testdir\ => testdir \testdir\test.exe => \testdir [objpas\fina.inc] function ExtractFileDir(const FileName: string): string; var i,j: longint; begin if FileName[2]=':' then j:=3 else j:=1; I := Length(FileName); while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I); if (I > j) and (FileName[I] in ['\', '/']) and not (FileName[I - 1] in ['/', '\', ':']) then Dec(I); Result := Copy(FileName, j, I-j+1); end; HTH, ivan ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]ExtractFileDir ?
Hi! Let's have a look for filename "C:A": > function ExtractFileDir(const FileName: string): string; > var i,j: longint; > begin >if FileName[2]=':' then j:=3 > else j:=1; Now j = 3, pointing to the letter "A". OK. >I := Length(FileName); >while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I); Error: I is supposed to go from the string end back to the string start, but never below j. But exactly this happens here. I is decremented below j, from 3 to 2, so shit might happen .. >if (I > j) and (FileName[I] in ['\', '/']) and > not (FileName[I - 1] in ['/', '\', ':']) then Dec(I); skipped >Result := Copy(FileName, j, I-j+1); Result = Copy(Filename, 3, 0). Is this an error or wrong documentation? The line result should be '', but it actually is 'a:c'. So there are two errors: 1. I decremented below j, but the programmer had in mind that i was above j. the while-statement should read 'while (I > J) ..' 2. The Copy returns the full string for length 0 - Note: I don't like the while structure for combined conditions. I prefer a repeat-until with several breaks. That usually makes things more clear. I know that this is not considered 'well-structured' programming, but the world we live in is not 'well-structured'. Should I post a new, tested "repeat - break - break - until" version of this function? Anton. > ___ > fpc-pascal maillist - [EMAIL PROTECTED] > http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]CompareStr
Hi, Maybe it's how it's supposed to be but if use : compareStr( 'hello', 'hello-bye' ) I get 0, so they are equal. If one string is bigger than the other they should be different, isn't it? Otherways what can I use to check if two ansistrings are different? TIA, Ivan ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]CompareStr
Iván Montes schrieb: Hi, Maybe it's how it's supposed to be but if use : compareStr( 'hello', 'hello-bye' ) I get 0, so they are equal. If one string is bigger than the other they should be different, isn't it? I think so, too... but I don't have time to check this now, sorry, hopefully somebody else has. Otherways what can I use to check if two ansistrings are different? You can just use "=" for ShortString, AnsiString and WideString comparisons. "=" just doesn't work for PChar or PWideChar strings. - Sebastian ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]test, don't worry, don't reply, remove
sorry list just a test ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]CompareStr
On Thu, Feb 13, 2003 at 02:49:49AM +0100, Iv?n Montes wrote: > Hi, > > Maybe it's how it's supposed to be but if use : > > compareStr( 'hello', 'hello-bye' ) > > I get 0, so they are equal. > > If one string is bigger than the other they should be different, isn't it? > > Otherways what can I use to check if two ansistrings are different? > > TIA, Ivan I think this may be a bug in the compareStr function of sysUtils. I have tested the compareStr of sysUtils, and the compStr of the Strings unit. The Strings unit seems to do the test ok, and the result: 'hello' < 'hello-byte'. cheers James program compare; (* uses sysUtils; *) uses Strings; var (* str1: String; str2: String; *) str1: pChar; str2: pChar; r:Integer; begin str1 := 'hello'; str2 := 'hello-bye'; writeLn('str1 = ', str1); writeLn('str2 = ', str2); writeLn; r := strComp(str1, str2); if r < 0 then begin writeLn('str1 < str2'); end else if r = 0 then begin writeLn('str1 = str2'); end else begin writeLn('str1 > str2'); end; end. > ___ > fpc-pascal maillist - [EMAIL PROTECTED] > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]ExtractFileDir ?
[OT: Sorry if this was posted before but I'm having some weird problems with email] According to the docs http://www.freepascal.org/docs-html/units/node23.html#SECTION0023660 00 "ExtractFileDir returns only the directory part of FileName, not including a driveletter." But it does return the driveletter, so either the docs are mistaken or the RTL. If the docs are right here there is a function that will return only the dir, removing any drive letter. ie: c:\testdir\test\file.ext => \testdir\test c:\testdir\ => \testdir c:testdir\ => testdir \testdir\test.exe => \testdir [objpas\fina.inc] function ExtractFileDir(const FileName: string): string; var i,j: longint; begin I := Length(FileName); if (I>1) and (FileName[2]=':') then j:=3 else j:=1; I := Length(FileName); while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I); if (I > j) and (FileName[I] in ['\', '/']) and not (FileName[I - 1] in ['/', '\', ':']) then Dec(I); Result := Copy(FileName, j, I-j+1); end; HTH, ivan ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]SysUtils.FileExists bug under Go32v2
Hi, I think I've found a bug on the FileExists function (sysutils) under Go32v2, when I want to check if a directory exists. FileExists( 'c:\winnt' ) will return False when compiled for Go32 but true for Win32. I guess that the Win32 version is doing rigth, since a directory is part of the file system. I've checked a recent CVS copy of the sources and I found this [go32v2/sysutls.pp] Function FileExists (Const FileName : String) : Boolean; var Handle: longint; begin //!! This can be done quicker, need to find out how Result := (OpenFile(FileName, Handle, ofRead, faOpen) = 0); if Handle <> 0 then FileClose(Handle); end; this could be changed for example to: Function FileExists (Const filename :String) :Boolean; begin //FileGetAttrib will return -1 if the file was not found //but I don't know if it will return -1 if the file exists but it's open by another program result := boolean( FileGetAttr( filename ) XOR -1 ); end; hope this helps, Ivan ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal