Browse Source

+ Initial implementation

michael 27 years ago
parent
commit
4ac979a4f0
1 changed files with 78 additions and 1 deletions
  1. 78 1
      fcl/inc/strings.inc

+ 78 - 1
fcl/inc/strings.inc

@@ -145,6 +145,7 @@ end;
 destructor TSTrings.Destroy; 
 destructor TSTrings.Destroy; 
 
 
 begin
 begin
+  inherited destroy;
 end;
 end;
 
 
 
 
@@ -152,6 +153,8 @@ end;
 Function TStrings.Add(const S: string): Integer; 
 Function TStrings.Add(const S: string): Integer; 
 
 
 begin
 begin
+  Result:=Count;
+  Insert (Count,S);
 end;
 end;
 
 
 
 
@@ -159,6 +162,8 @@ end;
 Function TStrings.AddObject(const S: string; AObject: TObject): Integer; 
 Function TStrings.AddObject(const S: string; AObject: TObject): Integer; 
 
 
 begin
 begin
+  Result:=Add(S);
+  Objects[result]:=AObject;
 end;
 end;
 
 
 
 
@@ -166,13 +171,18 @@ end;
 Procedure TStrings.Append(const S: string);
 Procedure TStrings.Append(const S: string);
 
 
 begin
 begin
+  Add (S);
 end;
 end;
 
 
 
 
 
 
 Procedure TStrings.AddStrings(TheStrings: TStrings); 
 Procedure TStrings.AddStrings(TheStrings: TStrings); 
 
 
+Var Runner : longint;
+
 begin
 begin
+  For Runner:=0 to TheStrings.Count-1 do
+    self.AddObject (Thestrings[Runner],TheStrings.Objects[Runner]);
 end;
 end;
 
 
 
 
@@ -180,6 +190,13 @@ end;
 Procedure TStrings.Assign(Source: TPersistent); 
 Procedure TStrings.Assign(Source: TPersistent); 
 
 
 begin
 begin
+  If Source is TStrings then
+    begin
+    clear;
+    AddStrings(TStrings(Source));
+    exit;
+    end;
+  Inherited Assign(Source);
 end;
 end;
 
 
 
 
@@ -200,14 +217,32 @@ end;
 
 
 Function TStrings.Equals(TheStrings: TStrings): Boolean;
 Function TStrings.Equals(TheStrings: TStrings): Boolean;
 
 
+Var Runner,Nr : Longint;
+
 begin
 begin
+  Result:=False;
+  Nr:=Self.Count;
+  if Nr<>TheStrings.Count then exit;
+  For Runner:=0 to Nr-1 do 
+    If Strings[Runner]<>TheStrings[Runner] then exit;
+  Result:=True;
 end;
 end;
 
 
 
 
 
 
 Procedure TStrings.Exchange(Index1, Index2: Integer); 
 Procedure TStrings.Exchange(Index1, Index2: Integer); 
 
 
+Var
+  Obj : TObject;
+  Str : String;
+
 begin
 begin
+  Obj:=Objects[Index1];
+  Str:=Strings[Index1];
+  Objects[Index1]:=Objects[Index2];
+  Strings[Index1]:=Strings[Index2];
+  Objects[Index2]:=Obj;
+  Strings[Index2]:=Str;
 end;
 end;
 
 
 
 
@@ -215,20 +250,35 @@ end;
 Function TStrings.GetText: PChar; 
 Function TStrings.GetText: PChar; 
 
 
 begin
 begin
+//!!  Result:=StrNew(Pchar(Self.Text));
 end;
 end;
 
 
 
 
 
 
 Function TStrings.IndexOf(const S: string): Integer; 
 Function TStrings.IndexOf(const S: string): Integer; 
 
 
+
 begin
 begin
+  Result:=0;
+  While (Result<Count) and (Strings[Result]<>S) do Result:=Result+1;
+  if Result=Count then Result:=-1;
 end;
 end;
 
 
 
 
 
 
 Function TStrings.IndexOfName(const Name: string): Integer;
 Function TStrings.IndexOfName(const Name: string): Integer;
 
 
+Var len : longint;
+
 begin
 begin
+  Result:=0;
+  while (Result<Count) do
+    begin
+    len:=pos('=',Strings[Result])-1;
+    if (len>0) and (Name=Copy(Strings[Result],1,Len)) then exit;
+    inc(result);
+    end;
+  result:=-1; 
 end;
 end;
 
 
 
 
@@ -236,6 +286,9 @@ end;
 Function TStrings.IndexOfObject(AObject: TObject): Integer;
 Function TStrings.IndexOfObject(AObject: TObject): Integer;
 
 
 begin
 begin
+  Result:=0;
+  While (Result<count) and (Objects[Result]<>AObject) do Result:=Result+1;
+  If Result=Count then Result:=-1;
 end;
 end;
 
 
 
 
@@ -244,13 +297,20 @@ Procedure TStrings.InsertObject(Index: Integer; const S: string;
   AObject: TObject);
   AObject: TObject);
 
 
 begin
 begin
+  Insert (Index,S);
+  Objects[Index]:=AObject;
 end;
 end;
 
 
 
 
 
 
 Procedure TStrings.LoadFromFile(const FileName: string); 
 Procedure TStrings.LoadFromFile(const FileName: string); 
 
 
+Var TheStream : TFileStream;
+
 begin
 begin
+  TheStream:=TFileStream.Create(FileName,fmOpenRead);
+  LoadFromStream(TheStream);
+  TheStream.Free;
 end;
 end;
 
 
 
 
@@ -258,20 +318,33 @@ end;
 Procedure TStrings.LoadFromStream(Stream: TStream); 
 Procedure TStrings.LoadFromStream(Stream: TStream); 
 
 
 begin
 begin
+  Text:=Stream.ReadAnsiString;
 end;
 end;
 
 
 
 
 
 
 Procedure TStrings.Move(CurIndex, NewIndex: Integer); 
 Procedure TStrings.Move(CurIndex, NewIndex: Integer); 
 
 
+Var Obj : TObject;
+    Str : String;
+
 begin
 begin
+   Obj:=Objects[CurIndex];
+   Str:=Strings[CurIndex];
+   Delete(Curindex);
+   InsertObject(NewIndex,Str,Obj);  
 end;
 end;
 
 
 
 
 
 
 Procedure TStrings.SaveToFile(const FileName: string); 
 Procedure TStrings.SaveToFile(const FileName: string); 
 
 
+Var TheStream : TFileStream;
+
 begin
 begin
+  TheStream:=TFileStream.Create(FileName,fmCreate);
+  SaveToStream(TheStream);
+  TheStream.Free;
 end;
 end;
 
 
 
 
@@ -279,6 +352,7 @@ end;
 Procedure TStrings.SaveToStream(Stream: TStream); 
 Procedure TStrings.SaveToStream(Stream: TStream); 
 
 
 begin
 begin
+  Stream.WriteAnsiString(Text);
 end;
 end;
 
 
 
 
@@ -462,7 +536,10 @@ begin
 end;
 end;
 {
 {
   $Log$
   $Log$
-  Revision 1.1  1998-05-04 14:30:12  michael
+  Revision 1.2  1998-05-06 12:58:53  michael
+  + Initial implementation
+
+  Revision 1.1  1998/05/04 14:30:12  michael
   * Split file according to Class; implemented dummys for all methods, so unit compiles.
   * Split file according to Class; implemented dummys for all methods, so unit compiles.
 
 
 }
 }