Re:Delphi routine Win3.11 for win.98
On Sun, 30 Sep 2001 11:36:26 -0300, "Fernando" <f...@bol.com.br>
wrote:
Quote
>I would like help.
>I have the routine below that it works well in Delphi with Win.3.11, but it
>doesn't work in
>win.95/98. I believe that a difference exists among Win.3.11 win.95/98 when
>it negotiates
>numbers and string.
>The routine below is used to limit the amount of times that a software can
>be used.
While the issue here is not really Delphi specific, it is pretty much
Borland compiler specific so you're posting on the wrong list for
this.
Delphi specific questions should be posted to one of the
comp.lang.pascal.delphi.* groups; other Borland compiler related
questions should go to comp.land.pascal.borland.
In any case, I suspect what you're running into is the more stringent
file sharing behavior in Win32 as compared with DOS/Win16.
By default the old-style file handling routines want to open an
untyped file in read/write mode; whereas Win32 generally prohibits
write mode on the .EXE file of a running executable.
Given your code, probably the simplest workaround is to set the
FileMode variable before opening the file, see below:
-------------------->8 cut here 8<--------------------
Quote
>function TForm1.Protect(QtProt:byte) : boolean;
>type
> tcfg = record
> id : string[10]; { badge to identify }
> val: byte;
> end;
>const
> { Id , Any string. To be researched inside of the file .EXE }
> cfg : tcfg = (id:'$2Act?2?'; val:4);
>var
> lixo : string[10];
> f : file;
> i : longint;
SaveMode : Byte;
Quote
>begin;
> Label1.Caption := 'They still remain: ' +
> inttostr(cfg.val) +
> 'Executions of a total of 4';
> if cfg.val > 0 then
> begin
> lixo := '';
SaveMode := FileMode; { save current mode }
FileMode := 0; { open read-only }
Quote
>{$I-}
> assignfile(f, paramstr(0));
> reset(f, 1);
> i := filesize(f) - sizeof(cfg);
>{$I+}
FileMode := SaveMode; { restore previous mode }
...
-------------------->8 cut here 8<--------------------
An alternative is to re-write your code using a TFileStream and use
fmOpenRead for the Mode parameter.
HTH
Stephen Posey
slpo...@concentric.net