[fpc-pascal] array & record output/input

Vannus vannus at gmail.com
Wed Jun 2 23:12:33 CEST 2010


On 2 June 2010 18:56, José Mejuto <joshyfun at gmail.com> wrote:

> Hello FPC-Pascal,
>
> Wednesday, June 2, 2010, 2:56:29 PM, you wrote:
>
> V> ooh. php has 'print_r' for printing arrays/objects - an equivalent
> V> ArrayToStr would be handy to have in Pascal. while pascal is my
> favourite
> V> language, I'm finding it poorly supported compared with php :(
>
>  That's not a matter of support,
>

maybe a poorly placed moan there... was getting annoyed with Indy/XML not
doing what I wanted.
i gave up trying to get XPath and XML Namespaces to work recently... whereas
ive had XPath+Namespaces working in php in the past...
in fairness it might be ok in FPC (although its not in the XML tutorial),
ive been using RAD 2010 because Indy WebDAV wasnt working in Lazarus :(


>   to writeln a record you must keep the
> structure information at runtime which is a must for scripted
> languages but it is not needed at all for a compiled one (native
> code). So if you keep that information people will complaint about
> memory footprint and compiler not hidding internal program structures
> and other now complaint about it can not writeln a record :-?
>

indeed, i would be complaining about size/speed.
thats a good point about what is known after compilation. does 'array of
string' just become a blob of memory, with no type information?
so the solution would be an overloaded ArrayToStr;
- ArrayToStr(AArray: string)
- ArrayToStr(AArray: int), etc?

that would output;
array {
  [0] => 'mystring'
}
array {
  [0] => 123
}

maybe a clever person could suggest how we could handle 'array of array of
array of x' and deeper ?


>
> If you want to do something like that replace yout records with
> classes and put the fileds in the published section so you will have
> RTTI information about the class and you can write a generic writeln
>  function for classes writting the published fields.


isn't there already something like this for writing .lfm files?


>
> --
> Best regards,
>  José
>

-V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100602/41b5ee68/attachment.html>


More information about the fpc-pascal mailing list