procedure TACEVCard.LoadFromFile(Filename: string);
var
I, V: TStrings;
FV, FFN, FN: Boolean;
A: Integer;
S, D1, D2: String;
begin
I := TStringList.Create;
V := TStringList.Create;
try
I.LoadFromFile(FileName);
I.Text := AnsiReplaceStr(I.Text, #13#10#32, '');
I.Text := AnsiReplaceStr(I.Text, #13#10#9, '');
A := I.Count;
if (I[1] <> 'BEGIN:VCARD') OR (I[A-1] <> 'END:VCARD') then
Raise EVCardLoadError.CreateFmt('%s is not a valid VCard File', [FileName]);
FV := False;
FFN := False;
FN := False;
for A := 0 to I.Count - 1 do
begin
if AnsiLeftStr(I[A], 8) = 'VERSION:' then FV := True;
if AnsiLeftStr(I[A], 3) = 'FN:' then FFN := True;
if AnsiLeftStr(I[A], 2) = 'N:' then FN := True;
end;
if NOT FV then
Raise EVCardLoadError.CreateFmt('%s does not contain a valid Version Identifier', [FileName]);
if NOT FFN then
Raise EVCardLoadError.CreateFmt('%s does not contain a valid Formatted Name Identifier', [FileName]);
if NOT FN then
Raise EVCardLoadError.CreateFmt('%s does not contain a valid Name Identifier', [FileName]);
FIdentInfo.LoadFromStringList(I);
FAddressInfo.LoadFromStringList(I);
FPhoneNumbers.LoadFromStringList(I);
FEmails.LoadFromStringList(I);
FAdditional.LoadFromStringList(I);
for A := 0 to I.Count - 1 do
begin
S := I[A];
if AnsiLeftStr(S, 8) = 'VERSION:' then
FVersion := Copy(S, 9, Length(S));
if AnsiLeftStr(S, 4) = 'REV:' then
begin
S := Copy(S, 5, Length(S));
if Pos('T', S) = 0 then
begin
D2 := '00:00:00';
V := Explode(S, '-');
D1 := V[2] + '-' + V[1] + '-' + V[0];
end
else
begin
V := Explode(Copy(S, 1, Pos('T', S) - 1), '-');
D1 := V[2] + '-' + V[1] + '-' + V[0];
D2 := Copy(S, Pos('T', S) + 1, Pos('Z', S) - 1);
end;
FRevision := StrToDateTime(D1 + ' ' + D2);
end;
end;
finally
I.Free;
V.Free;
end;
end;