Board index » delphi » Delphi routine Win3.11 for win.98

Delphi routine Win3.11 for win.98

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.
of course !
Tks
Fernando.
-----------------------------------------------------
unit Unit1;

interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    procedure FormActivate(Sender: TObject);
    function Protect(QtProt:byte) : boolean;
  private
    { Private declarations }
 //   function Protect(QtProt:byte) : boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}
{---------------------------------------------------------------------------

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;
begin;
  Label1.Caption := 'They still remain: ' +
                    inttostr(cfg.val) +
                    'Executions of a total of 4';
  if cfg.val > 0 then
  begin
    lixo := '';
{$I-}
    assignfile(f, paramstr(0));
    reset(f, 1);
    i := filesize(f) - sizeof(cfg);
{$I+}
    { I seek the badge. }
    while (i > 0) and (lixo <> '$2Act?2?') do
    begin
      seek(f, i);
      blockread(f, lixo, sizeof(lixo));
      dec(i);
    end;

    if (i > 0) then
    begin  { If I found the badge... }
      seek(f, succ(i));
      if (cfg.val > 0) then
      begin
        dec(cfg.val);
        blockwrite(f, cfg, sizeof(cfg));
      end;
    end;
{$I-}
    closefile(f);
    Protect := false;
{$I+}

  end else
    Protect := True;
end;
{---------------------------------------------------------------------------

Quote
}

procedure TForm1.FormActivate(Sender: TObject);
begin
  if Protect(4) then
    Label2.Caption := 'ATTENTION: It cannot Be executed'
  else
    Label2.Caption := 'Allowed execution';
end;
{---------------------------------------------------------------------------

Quote
}

end.
 

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

Re:Delphi routine Win3.11 for win.98


Quote
Stephen Posey wrote:

... snip ...>
> 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:

All the Borland products opened all files for read/write by
default, and this produces various problems [1].  I always used to
set filemode := 0 at program startup by default.  This doesn't
prevent opening a writable file, with rewrite.

1. For example, run an unfixed program, and have it open a file
   marked r/o with reset (for read).

--
Chuck F (cbfalco...@yahoo.com) (cbfalco...@XXXXworldnet.att.net)
   (Remove "XXXX" from reply address. yahoo works unmodified)
   mailto:u...@ftc.gov  (for spambots to harvest)

Other Threads