Path: utzoo!attcan!uunet!mcvax!enea!tut!santra!k34386t From: k34386t@kaira.HUT.FI (Petri Kruiseri Suominen) Newsgroups: comp.lang.pascal Subject: Re: How to find declared length of strings in TP 4.0 ?? Message-ID: <14475@santra.UUCP> Date: 12 Jul 88 20:47:35 GMT References: <16378@brl-adm.ARPA> <950011@hpclldw.HP.COM> Sender: news@santra.UUCP Reply-To: k34386t@kaira.UUCP (Petri Kruiseri Suominen) Organization: Helsinki University of Technology, Finland Lines: 35 In article <950011@hpclldw.HP.COM> ldw@hpclldw.HP.COM (Larry Woods) writes: >Do you mean at runtime? The answer is that you don't. It isn't stored >anywhere for implementations of Pascal I'm familiar with. It is merely >passed as a value parameter to run time routines for checking purposes. However, there is a way to find it out, allthough it's not very 'professional' TP 4.0 cuts a string if a string longer than its declared length is assigned to it. So you could write a function something like this ------------------------------- Cut Here -------------------------------- Function length_of_string(characters:string):integer; var counter:integer; another_string:string; begin another_string:=''; for counter:=1 to 255 do another_string:=another_string+' '; another_string:=another_string+characters; length_of_string:=length(another_string); end; ------------------------------ Cut Here ------------------------------------ As you can see, the idea is to add enough blanks to the string, that it surely exceeds 255 which is the maximum length of a string in TP 4.0 . Since TP cuts a string at the declared length of the string, testing for the length of the string with the blanks added returns the declared length of the string. No testing was done with this code, but I would like to know if it works.