Recent

Author Topic: Is there a component to Read in/ write out a VCard file  (Read 6504 times)

WTDdallas

  • Full Member
  • ***
  • Posts: 100
Is there a component to Read in/ write out a VCard file
« on: May 29, 2016, 04:39:46 am »
Is there a component to Read in/ write out a VCard file(.vcf)??

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: Is there a component to Read in/ write out a VCard file
« Reply #1 on: May 29, 2016, 09:08:56 am »
Is there a component to Read in/ write out a VCard file(.vcf)??

Not that I know, but there is this one for Delphi:
http://torry.net/quicksearchd.php?String=ACEVCard&Title=Yes
Specialize a type, not a var.

WTDdallas

  • Full Member
  • ***
  • Posts: 100
Re: Is there a component to Read in/ write out a VCard file
« Reply #2 on: May 29, 2016, 03:19:22 pm »
Is there a component to Read in/ write out a VCard file(.vcf)??

Not that I know, but there is this one for Delphi:
http://torry.net/quicksearchd.php?String=ACEVCard&Title=Yes

Thanks downloaded it , No Examples  :(

It seems to be written for Delphi.  :(

Is there one written for Lazarus?

Seems most of the Products for sale on that site, their websites are not longer around.  :(

balazsszekely

  • Guest
Re: Is there a component to Read in/ write out a VCard file
« Reply #3 on: May 29, 2016, 03:26:56 pm »
Quote
@WTDallas
Is there one written for Lazarus?
Did you try to convert it? It shouldn't be to difficult.

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Is there a component to Read in/ write out a VCard file
« Reply #4 on: May 29, 2016, 04:45:09 pm »
Just visually inspected that source and IMO, that should work out of the box on lazarus. There's nothing platform specific inside ... just remove Windows and Messages unit and that's it.

WTDdallas

  • Full Member
  • ***
  • Posts: 100
Re: Is there a component to Read in/ write out a VCard file
« Reply #5 on: May 29, 2016, 06:52:52 pm »
Quote
@WTDallas
Is there one written for Lazarus?
Did you try to convert it? It shouldn't be to difficult.

Not yet, but I will, I just saw the .dcu files. Will have to figure out how to use it, no examples included.
« Last Edit: May 29, 2016, 08:25:11 pm by WTDdallas »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Is there a component to Read in/ write out a VCard file
« Reply #6 on: May 29, 2016, 08:30:10 pm »
ACEVCCls.pas -> compiles straight
ACEVCard.pas -> remove Windows and Messages, replace GetLastError with GetLastOSError
Use mode delphi when compiling of course

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Is there a component to Read in/ write out a VCard file
« Reply #7 on: May 29, 2016, 11:14:04 pm »
In addition to what Leledumbo wrote:
- Mode OBJFPC also works
- With respect to original author: The code is buggy and contains logical errors.

So either you need to correct the mistakes or try create your own (i was unable to locate another vcard implementation in pascal)

Some issues:
Code: Pascal  [Select][+][-]
  1. {Explode any string to a TStringSet, using Delim as a splitter,
  2.   unless the Delim Character is escaped}
  3. Function Explode(Input: String; Delim: Char): TStrings;
  4. var
  5.   P: Integer;
  6.   UnEsc: String;
  7.   Sub: String;
  8. begin
  9.   Result := nil;
  10.   if Delim = '%' then Sub := '$ESCAPEDCHAR$' else Sub := '%ESCAPEDCHAR%';
  11.   Result.Clear;
  12.   UnEsc := AnsiReplaceText(Input, '\' + Delim, Sub);
  13.   while Pos(Delim, UnEsc) > 0 do
  14.   begin
  15.     P := Pos(Delim, UnEsc);
  16.     Result.Add(Copy(UnEsc, 1, P-1));
  17.     Delete(UnEsc, 1, P);
  18.   end;
  19.   if UnEsc <> '' then Result.Add(UnEsc);
  20.   for P := 0 to Result.Count - 1 do
  21.     Result.Strings[P] := AnsiReplaceText(Result.Strings[P], Sub, '\' + Delim);
  22. end;
  23.  

Code: Pascal  [Select][+][-]
  1. procedure TACEVCard.LoadFromFile(Filename: string);
  2. var
  3.   I, V: TStrings;
  4.   FV, FFN, FN: Boolean;
  5.   A: Integer;
  6.   S, D1, D2: String;
  7. begin
  8.   I := TStringList.Create;
  9.   V := TStringList.Create;
  10.   try
  11.     I.LoadFromFile(FileName);
  12.     I.Text := AnsiReplaceStr(I.Text, #13#10#32, '');
  13.     I.Text := AnsiReplaceStr(I.Text, #13#10#9, '');
  14.     A := I.Count;
  15.    
  16.     if (I[1] <> 'BEGIN:VCARD') OR (I[A-1] <> 'END:VCARD') then
  17.     Raise EVCardLoadError.CreateFmt('%s is not a valid VCard File', [FileName]);
  18.    
  19.     FV := False;
  20.     FFN := False;
  21.     FN := False;
  22.     for A := 0 to I.Count - 1 do
  23.     begin
  24.       if AnsiLeftStr(I[A], 8) = 'VERSION:' then FV := True;
  25.       if AnsiLeftStr(I[A], 3) = 'FN:' then FFN := True;
  26.       if AnsiLeftStr(I[A], 2) = 'N:' then FN := True;
  27.     end;
  28.     if NOT FV then
  29.       Raise EVCardLoadError.CreateFmt('%s does not contain a valid Version Identifier', [FileName]);
  30.     if NOT FFN then
  31.       Raise EVCardLoadError.CreateFmt('%s does not contain a valid Formatted Name Identifier', [FileName]);
  32.     if NOT FN then
  33.       Raise EVCardLoadError.CreateFmt('%s does not contain a valid Name Identifier', [FileName]);
  34.     FIdentInfo.LoadFromStringList(I);
  35.     FAddressInfo.LoadFromStringList(I);
  36.     FPhoneNumbers.LoadFromStringList(I);
  37.     FEmails.LoadFromStringList(I);
  38.     FAdditional.LoadFromStringList(I);
  39.     for A := 0 to I.Count - 1 do
  40.     begin
  41.       S := I[A];
  42.       if AnsiLeftStr(S, 8) = 'VERSION:' then
  43.         FVersion := Copy(S, 9, Length(S));
  44.       if AnsiLeftStr(S, 4) = 'REV:' then
  45.       begin
  46.         S := Copy(S, 5, Length(S));
  47.         if Pos('T', S) = 0 then
  48.         begin
  49.           D2 := '00:00:00';
  50.           V := Explode(S, '-');
  51.           D1 := V[2] + '-' + V[1] + '-' + V[0];
  52.         end
  53.         else
  54.         begin
  55.           V := Explode(Copy(S, 1, Pos('T', S) - 1), '-');
  56.           D1 := V[2] + '-' + V[1] + '-' + V[0];
  57.           D2 := Copy(S, Pos('T', S) + 1, Pos('Z', S) - 1);
  58.         end;
  59.         FRevision := StrToDateTime(D1 + ' ' + D2);
  60.       end;
  61.     end;
  62.   finally
  63.     I.Free;
  64.     V.Free;
  65.   end;
  66. end;
  67.  

As for an example (FPC commandline):

Code: [Select]
program testvcard;

{$MODE OBJFPC}{$H+}

Uses
  AceVCard;


Procedure Test(FileName: string);
Var
  VCard: TAceVCard;
begin
  WriteLn;
  WriteLn('###### ', FileName, ' #####');
  WriteLn;

  VCard := TAceVCard.Create(nil);
  VCard.LoadFromFile(Filename);

  with VCard.Personal do
  begin
    with Name do
    begin
      WriteLn('VCard.Personal.Name.FamilyName               = ', FamilyName);
      WriteLn('VCard.Personal.Name.GivenName                = ', GivenName);
      WriteLn('VCard.Personal.Name.AdditionalNames          = ', AdditionalNames);
      WriteLn('VCard.Personal.Name.Prefix                   = ', Prefix);
      WriteLn('VCard.Personal.Name.Suffix                   = ', Suffix);
    end;

    WriteLn('VCard.Personal.FormattedName                 = ', FormattedName);
    WriteLn('VCard.Personal.SortString                    = ', SortString);

    with Company do
    begin
      WriteLn('VCard.Personal.Company.CompanyName           = ', CompanyName);
      WriteLn('VCard.Personal.Company.CompanyUnit           = ', CompanyUnit);
      WriteLn('VCard.Personal.Company.SubUnit1              = ', SubUnit1);
      WriteLn('VCard.Personal.Company.SubUnit2              = ', SubUnit2);
      WriteLn('VCard.Personal.Company.SubUnit3              = ', SubUnit3);
      WriteLn('VCard.Personal.Company.SubUnit4              = ', SubUnit4);
      WriteLn('VCard.Personal.Company.Title                 = ', Title);
      WriteLn('VCard.Personal.Company.Role                  = ', Role);
    end;
  end;

  with VCard.Addresses do
  begin
    With Address1 do
    begin
      WriteLn('VCard.Addresses.Address1.Attributes          = ', Integer(Attributes));
      WriteLn('VCard.Addresses.Address1.Postbox             = ', PostBox);
      WriteLn('VCard.Addresses.Address1.ExtendedAddress     = ', ExtendedAddress);
      WriteLn('VCard.Addresses.Address1.Street              = ', Street);
      WriteLn('VCard.Addresses.Address1.Localeity           = ', Locality);
      WriteLn('VCard.Addresses.Address1.Region              = ', Region);
      WriteLn('VCard.Addresses.Address1.PostalCode          = ', PostalCode);
      WriteLn('VCard.Addresses.Address1.Country             = ', Country);
    end;   
    // there are 3 additional addresess
  end;

  with VCard.PhoneNumbers do
  begin
    with Phone1 do
    begin
      WriteLn('VCard.PhoneNumbers.Phone1.Attributes         = ', Integer(Attributes));
      WriteLn('VCard.PhoneNumbers.Phone1.Number             = ', Number);
    end;
    // there are 7 additional numbers.
  end;

  with VCard.EMailAddresses do
  begin
    with EmailAddress1 do
    begin
      WriteLn('VCard.EMailAddresses.EmailAddress1.EmailType = ', Ord(EmailType));
      WriteLn('VCard.EMailAddresses.EmailAddress1.Address   = ', Address);
    end;
    // there are 7 additional email addresses
  end;

  with VCard.Additional do
  begin
    WriteLn('VCard.Additional.Comment                     = ', Comment.Text);
    WriteLn('VCard.Additional.URL1                        = ', URL1);
    WriteLn('VCard.Additional.URL2                        = ', URL2);
  end;

  Writeln('VCard.Version                                = ', VCard.Version);
  Writeln('VCard.Revision                               = ', VCard.Revision);

  VCard.Free;
end;


begin
  Test('examples1/john-doe.vcf');
end.
« Last Edit: May 29, 2016, 11:41:35 pm by molly »

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Is there a component to Read in/ write out a VCard file
« Reply #8 on: February 18, 2023, 05:51:30 pm »
Maybe there is something new in the recent years?

Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Is there a component to Read in/ write out a VCard file
« Reply #9 on: February 18, 2023, 06:12:20 pm »
Looks like a spam generator!
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Is there a component to Read in/ write out a VCard file
« Reply #10 on: February 18, 2023, 06:16:09 pm »
VCard files are supported by TvPlanIt, units VpBaseDataFiles and VpVCard (there is some dependence on other TvPlanIt units, but i think this can be circumvented easily).

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Is there a component to Read in/ write out a VCard file
« Reply #11 on: February 18, 2023, 06:19:00 pm »
whats the big deal here?
https://en.wikipedia.org/wiki/VCard
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018