Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-11

Assign not working on text files

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stefanos Beligiannis
If somebody has met this problem please advise.
----------------code var?? ?f : text;
??? fn,nam : string;
??
begin
???? fn:=Edit2.Caption;
???? {$I-}
???? assign(f,fn);
???? if (not FileExists(fn)) then Rewrite(f) else Append(f);
???? {$I+}----------------- end codecompiler error report-----------------??startk2u.pas(92,18) Error: Wrong number of parameters specified for call to "Assign"k2u.pas(93,44) Hint: Local variable "f" does not seem to be initialized----------------- end
use Lazarus # 1.2.6

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141109/4e7e3c76/attachment.html>

Reply by email

Bart
to Stefanos Beligiannis
Stefanos Beligiannis wrote 17 lines
If somebody has met this problem please advise. ----------------code var f : text; fn,nam : string; begin fn:=Edit2.Caption; {$I-} assign(f,fn); if (not FileExists(fn)) then Rewrite(f) else Append(f); {$I+}----------------- end codecompiler error report----------------- startk2u.pas(92,18) Error: Wrong number of parameters specified for call to "Assign"k2u.pas(93,44) Hint: Local variable "f" does not seem to be initialized----------------- end use Lazarus # 1.2.6

Use TextFile instead of Text, use AssignFile instead of Assign. Alternatively prepend both Text and Assign with system. (note the dot!).

Bart

Reply by email

Michael Van Canneyt
to Bart
Bart wrote 22 lines
On 11/9/14, Stefanos Beligiannis wrote: > If somebody has met this problem please advise. > ----------------code var f : text; > fn,nam : string; > > begin > fn:=Edit2.Caption; > {$I-} > assign(f,fn); > if (not FileExists(fn)) then Rewrite(f) else Append(f); > {$I+}----------------- end codecompiler error > report----------------- startk2u.pas(92,18) Error: Wrong number of > parameters specified for call to "Assign"k2u.pas(93,44) Hint: Local variable > "f" does not seem to be initialized----------------- end > use Lazarus # 1.2.6 > > > Use TextFile instead of Text, use AssignFile instead of Assign. Alternatively prepend both Text and Assign with system. (note the dot!).

Explanation:

The code most likely is inside a TForm. TForm descends from TPersistent. TPersistent has a .Assign() method, which is totally unrelated to the Assign() of the system unit.

When compiling your code, the compiler needs to know which Assign() to use. It finds first the TPersistent.Assign, stops searching and gives an error because it has different arguments from the system version.

By prepending your "text" and "assign" with system: system.text, system.assign, the compiler does not search in TPersistent and finds the correct routines.

Michael.

Reply by email