From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 5 May 93 19:35:50 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: Variable length strings?? Message-ID: List-Id: In article <1993May5.104941.14603@comp.lancs.ac.uk> marc@comp.lancs.ac.uk (Marc Goldman) writes: > I am reading paths from a configuration file for the system i'm > writing, these paths are not of a set length, as they will depend > on where the system is installed. > I'm reading them into a long string, but ideally i need the > string to be the exact same length as the path. And i need this > string variable to be globally readable, not just for the scope > of a particular function/procedure. > Any suggestions?? i've been messing with descriminate record > types, but with no success so far. First of all, this application seems to be perfect for some global access-to-string variables: type String_Pointer is access String; ... Path: String_Pointer := ...; The only problem is that occasionally you will need to reference Path.all instead of Path. But the interesting trick come in the initial value. You imply that this should be read in during elaboration time. (i.e. Path will appear in a library package specification, and you want all references to Path to "work.") However none of the Get operations in Text_IO is a function, so you need to roll your own: with Text_IO; function Get_Path return String is Temp: String(1..250); Last: Integer; begin Text_IO.Get_Line(Temp,Last); return Temp(1..Last); end Get_Path; (You might want to fancy it up by adding a prompt, a file parameter, exception support, or handling of very long lines.) Add appropriate with clauses and pragma ELABORATEs, and you are all set to go. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...