Changeset 91 for trunk/UContact.pas
- Timestamp:
- Feb 2, 2022, 4:33:25 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r90 r91 141 141 class destructor Destroy2; 142 142 procedure SaveToStrings(Output: TStrings); 143 function LoadFromStrings(Lines: TStrings; StartLine: Integer = 0): Integer;143 function LoadFromStrings(Lines: TStrings; var StartLine: Integer): Boolean; 144 144 procedure SaveToFile(FileName: string); 145 145 procedure LoadFromFile(FileName: string); … … 1134 1134 end; 1135 1135 end; 1136 if LinePrefix <> '' then Add('');1137 1136 end; 1138 1137 end; … … 1141 1140 end; 1142 1141 1143 function TContact.LoadFromStrings(Lines: TStrings; StartLine: Integer = 0): Integer;1142 function TContact.LoadFromStrings(Lines: TStrings; var StartLine: Integer): Boolean; 1144 1143 type 1145 1144 TParseState = (psNone, psInside, psFinished); … … 1154 1153 Names: string; 1155 1154 begin 1155 Result := False; 1156 1156 ParseState := psNone; 1157 1157 I := StartLine; … … 1166 1166 end else begin 1167 1167 ContactsFile.Error(SExpectedVCardBegin, I + 1); 1168 I := -1;1169 1168 Break; 1170 1169 end; … … 1174 1173 ParseState := psFinished; 1175 1174 Inc(I); 1175 Result := True; 1176 1176 Break; 1177 1177 end else … … 1182 1182 while True do begin 1183 1183 Inc(I); 1184 if I >= Lines.Count then Break; 1184 1185 Line2 := Lines[I]; 1185 if (Length(Line s[I]) > 0) and (Line2[1] = ' ') then begin1186 Value := Value + Trim(Line s[I]);1186 if (Length(Line2) > 0) and (Line2[1] = ' ') then begin 1187 Value := Value + Trim(Line2); 1187 1188 end else 1188 if (Length(Line s[I]) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and1189 (Line s[I][1] = '=') then begin1190 Value := Value + Copy(Trim(Line s[I]), 2, MaxInt);1189 if (Length(Line2) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and 1190 (Line2[1] = '=') then begin 1191 Value := Value + Copy(Trim(Line2), 2, MaxInt); 1191 1192 end else begin 1192 1193 Dec(I); … … 1208 1209 end else begin 1209 1210 ContactsFile.Error(SExpectedProperty, I + 1); 1210 I := -1;1211 1211 Break; 1212 1212 end; … … 1214 1214 Inc(I); 1215 1215 end; 1216 Result:= I;1216 if Result then StartLine := I; 1217 1217 end; 1218 1218 … … 1233 1233 var 1234 1234 Lines: TStringList; 1235 StartLine: Integer; 1235 1236 begin 1236 1237 Lines := TStringList.Create; … … 1245 1246 end; 1246 1247 {$ENDIF} 1247 LoadFromStrings(Lines); 1248 StartLine := 0; 1249 LoadFromStrings(Lines, StartLine); 1248 1250 finally 1249 1251 Lines.Free; … … 1285 1287 Contact: TContact; 1286 1288 I: Integer; 1287 NewI: Integer;1288 1289 begin 1289 1290 Contacts.Clear; … … 1293 1294 Contact := TContact.Create; 1294 1295 Contact.ContactsFile := Self; 1295 NewI := Contact.LoadFromStrings(Lines, I); 1296 if NewI <= Lines.Count then begin 1297 if NewI <> -1 then begin 1298 Contacts.Add(Contact); 1299 I := NewI; 1300 end else begin 1301 FreeAndNil(Contact); 1302 Inc(I); 1303 end; 1296 if Contact.LoadFromStrings(Lines, I) then begin 1297 Contacts.Add(Contact); 1304 1298 end else begin 1305 1299 FreeAndNil(Contact); 1306 Break;1300 Inc(I); 1307 1301 end; 1308 1302 end;
Note:
See TracChangeset
for help on using the changeset viewer.