twriter.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2000 by Michael Van Canneyt and Florian Klaempfl
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. (*Procedure TTextWriter.WriteLn(Const Msg : String);
  12. Const CRLF = #10;
  13. begin
  14. Write(Msg+CRLF);
  15. end;
  16. Procedure TTextWriter.Write(Const Msg : String);
  17. Var S : String;
  18. begin
  19. S:=FPrefix+Msg;
  20. FStream.Write(Pointer(S)^,Length(S));
  21. end;
  22. Procedure TTextWriter.WriteFmt(Fmt : String; Args : Array of const);
  23. begin
  24. Writeln(Format(Fmt,Args));
  25. end;
  26. Procedure TTextWriter.StartObject(Const AClassName, AName : String);
  27. begin
  28. WriteFmt('Object %s %s',[AName,AClassName]);
  29. FPrefix:=FPrefix+' ';
  30. end;
  31. Procedure TTextWriter.EndObject;
  32. Var L : longint;
  33. begin
  34. L:=Length(FPrefix);
  35. If L>2 Then
  36. SetLength(FPrefix,L-2);
  37. Writeln('end');
  38. end;
  39. Procedure TTextWriter.StartCollection(Const AName : String);
  40. begin
  41. WriteFmt('%s = (',[AName]);
  42. FPrefix:=FPrefix+' ';
  43. end;
  44. Procedure TTextWriter.StartCollectionItem;
  45. begin
  46. end;
  47. Procedure TTextWriter.EndCollectionItem;
  48. begin
  49. end;
  50. Procedure TTextWriter.EndCollection;
  51. Var L : longint;
  52. begin
  53. L:=Length(FPrefix);
  54. If L>2 Then
  55. SetLength(FPrefix,L-2);
  56. Writeln(')');
  57. end;
  58. Procedure TTextWriter.WritePropName(const PropName: string);
  59. begin
  60. Writeln(PropName);
  61. end;
  62. Constructor TTextWriter.Create(S : TStream);
  63. begin
  64. Inherited Create;
  65. FStream:=S;
  66. FPrefix:='';
  67. end;
  68. Destructor TTextWriter.Destroy;
  69. begin
  70. end;
  71. Procedure TTextWriter.WriteIntegerProperty(Const Name : Shortstring;Value : Longint);
  72. begin
  73. WriteFmt('%s = %d',[Name,Value]);
  74. end;
  75. Procedure TTextWriter.WriteSetProperty (Const Name : ShortString;Value : longint; BaseType : TTypeInfo);
  76. begin
  77. //!! needs implementing.
  78. WriteFmt('%s = []',[Name]);
  79. end;
  80. Procedure TTextWriter.WriteEnumerationProperty (Const Name : ShortString;Value : Longint; Const EnumName : ShortSTring);
  81. begin
  82. WriteFmt('%s = %s',[Name,EnumName])
  83. end;
  84. Procedure TTextWriter.WriteStringProperty(Const Name : ShortString; Const Value : String);
  85. Type
  86. TMode = (quoted,unquoted);
  87. Var
  88. Mode : TMode;
  89. S : String;
  90. I,L : Longint;
  91. c : char;
  92. Procedure Add (A : String);
  93. begin
  94. S:=S+A;
  95. end;
  96. begin
  97. L:=Length(Value);
  98. Mode:=unquoted;
  99. S:=Name+' = ';
  100. For I:=1 to L do
  101. begin
  102. C:=Value[i];
  103. If (ord(C)>31) and (Ord(c)<=128) and (c<>'''') then
  104. begin
  105. If mode=Quoted then
  106. Add(c)
  107. else
  108. begin
  109. Add(''''+c);
  110. mode:=quoted
  111. end
  112. end
  113. else
  114. begin
  115. If Mode=quoted then
  116. begin
  117. Add('''');
  118. mode:=unquoted;
  119. end;
  120. Add(Format('#%d',[ord(c)]));
  121. end;
  122. If Length(S)>72 then
  123. begin
  124. if mode=quoted then
  125. Add ('''');
  126. Add('+');
  127. Writeln(S);
  128. Mode:=unQuoted;
  129. end;
  130. end;
  131. if mode=quoted then Add('''');
  132. Writeln(S);
  133. end;
  134. Procedure TTextWriter.WriteFloatProperty(Const Name : ShortString; Value : Extended);
  135. begin
  136. WriteFmt('%s = %e',[Name,Value])
  137. end;
  138. Procedure TTextWriter.WriteCollectionProperty(Const Name : ShortString;Value : TCollection);
  139. begin
  140. end;
  141. Procedure TTextWriter.WriteClassProperty(Instance : TPersistent;Propinfo :PPropInfo);
  142. begin
  143. end;
  144. Procedure TTextWriter.WriteComponentProperty(Const Name : ShortSTring; Value : TComponent);
  145. begin
  146. WriteFmt ('%s = %s',[Name,Value.Name]);
  147. end;
  148. Procedure TTextWriter.WriteNilProperty(Const Name : Shortstring);
  149. begin
  150. system.Writeln(stderr,'Nil : ',Name);
  151. WriteFmt ('%s = Nil',[Name])
  152. end;
  153. Procedure TTextWriter.WriteMethodProperty(Const Name,AMethodName : ShortString);
  154. begin
  155. WriteFmt ('%s = %s',[Name,AMethodName]);
  156. end;*)
  157. {
  158. $Log$
  159. Revision 1.1 2003-10-06 21:01:06 peter
  160. * moved classes unit to rtl
  161. Revision 1.3 2002/09/07 15:15:26 peter
  162. * old logs removed and tabs fixed
  163. }