Article View: comp.lang.pascal.borland
Article #398Re: function StringOf
From: Osmo Ronkanen
Date: Sun, 27 Dec 1998 00:00
Date: Sun, 27 Dec 1998 00:00
99 lines
3776 bytes
3776 bytes
In article <765j75$mg7@enews4.newsguy.com>, Quality <quality@annex.com> wrote:
>Mike:
>
>I've been programming high-level languages for over 25 years. I appreciate
>the beginner help anyways. You should know however that there is very little
>a programmer cannot do if they are willing to get their hands dirty and get
>into the nitty gritty of the machine. Also, building a string in the manner
>you describe does not allow for the "tabbing" function built into writeln
> aVariableAnyType:8 ).
Sure you can do it. You just need to write your own compiler that does
it. The fact is that TP does not allow the user to write functions or
procedures that have variable number and variable types of parameters.
You can write functions that convert value to string and use them when
concatenating the strings.
function strf(x:integer):string;
var s:string;
begin
str(x,s);
strf:=s;
End;
function strff(x:integer;field:word):string;
var s:string;
begin
str(x:field,s);
strff:=s;
End;
>
>What I do NOT know much about is PC/ASM coding (my experience is mostly
>mainframe). Maybe if someone knows how the compiler does this complex
>(variable-multiple) parameter stuff it could be adapted into an external
>unit or even maybe somehow the code could be "borrowed" or "piggy-backed"
>from the compiler via a reverse-patch or proc-ptr ? Anybody know how to do
>this in TP7 ?
The whole point is that the compiler does this. for example is you
have:
Writeln('The value is ',x);
then the compiler changes this to something like:
WriteString(output,'The value is ');
writeint(output,x);
WriteLine(output);
This is just an example and the above names are my invention but it
illustrates how it is done.
The closest you could come is by writing a text file driver and then
outputting to it. You still would not get the answer like you get one
from a function.
>
>If I create a new texfile, writeln a complex parameter as a line to that
>file, then reset and readln back that data as a string I can accomplish what
>I want. What I would like is a way to do this as a single function without
>accessing the disk. Barring the single function, what about a simple routine
>to create a small "virtual file" in RAM big enough to handle a string
>variable?
Believe it, there is no nice way to do that. Instead if trying to take
something from other compiler, use the tools that Borland gives to you.
I have also used following in case of printer output
Const MoveToDotX=#27'*p#X';
... Several similar constants where # represents the parameter
and then
type sst=string[25];
Procedure InsSt(var template:sst;{$ifdef ver70}const{$endif} s:sst);
var i:integer;
begin
i:=pos('#',template);
if i>0 then begin
delete(template,i,1);
insert(s,template,i);
End;
end;
Function wp(template:sst; value:word): sst;
var s:string[5];
begin
str(value,s);
InsSt(template,s);
wp:=template;
End;
And then use for example: Write(lst,wp(MoveToDotX, hposit));
Osmo
Technical Details
Message-ID:
<765u44$r2g@kruuna.Helsinki.FI>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<763sl2$v0@enews2.newsguy.com> <MPG.10ef42a8411e60b5989ad6@news.primenet.com> <765j75$mg7@enews4.newsguy.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,f9d88b35457e1f1d X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,f9d88b35457e1f1d X-Google-Attributes: gid108ebd,public X-Google-Thread: 10261c,f9d88b35457e1f1d X-Google-Attributes: gid10261c,public From: ronkanen@cc.helsinki.fi (Osmo Ronkanen) Subject: Re: function StringOf Date: 1998/12/27 Message-ID: <765u44$r2g@kruuna.Helsinki.FI> X-Deja-AN: 426212230 References: <763sl2$v0@enews2.newsguy.com> <MPG.10ef42a8411e60b5989ad6@news.primenet.com> <765j75$mg7@enews4.newsguy.com> Organization: University of Helsinki Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal,comp.lang.pascal.misc