Changeset 31 for trunk/UAcronym.pas


Ignore:
Timestamp:
Jul 13, 2016, 10:34:13 AM (8 years ago)
Author:
chronos
Message:
  • Added: Import format for MS Access database.
  • Added: Show text hints on toolbar buttons.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UAcronym.pas

    r30 r31  
    77uses
    88  Classes, SysUtils, Contnrs, XMLConf, XMLRead, XMLWrite, DOM, UXMLUtils,
    9   SpecializedList, fphttpclient, Dialogs;
     9  SpecializedList, fphttpclient, Dialogs, odbcconn, sqldb;
    1010
    1111type
     
    132132  end;
    133133
     134  TImportFormatKind = (ifkParse, ifkMSAccess);
     135
    134136  { TImportFormat }
    135137
     
    137139    Id: Integer;
    138140    Name: string;
     141    Kind: TImportFormatKind;
    139142    Block: TImportPattern;
    140143    ItemPatterns: TImportPatterns;
     
    172175    function DownloadHTTP(URL: string; Stream: TStream): Boolean;
    173176    procedure Process;
     177    procedure ProcessTextParse;
     178    procedure ProcessMSAccess;
    174179    procedure Assign(Source: TImportSource);
    175180    procedure SaveToNode(Node: TDOMNode);
     
    230235end;
    231236
     237{ TImportSourceMSAccess }
     238
     239procedure TImportSource.ProcessMSAccess;
     240var
     241  ODBCConnection1: TODBCConnection;
     242  SQLTransaction1: TSQLTransaction;
     243  SQLQuery1: TSQLQuery;
     244  NewAcronym: TAcronymEntry;
     245begin
     246  ItemCount := 0;
     247  ODBCConnection1 := TODBCCOnnection.Create(nil);
     248  SQLQuery1 := TSQLQuery.Create(nil);
     249  SQLTransaction1 := TSQLTransaction.Create(nil);
     250  try
     251    ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb, *.accdb)';
     252    ODBCConnection1.Params.Add('DBQ=' + URL);
     253    ODBCConnection1.Params.Add('Locale Identifier=1031');
     254    ODBCConnection1.Params.Add('ExtendedAnsiSQL=1');
     255    ODBCConnection1.Params.Add('CHARSET=ansi');
     256    ODBCConnection1.Connected := True;
     257    ODBCConnection1.KeepConnection := True;
     258
     259    SQLTransaction1.DataBase := ODBCConnection1;
     260    SQLTransaction1.Action := caCommit;
     261    SQLTransaction1.Active := True;
     262
     263    SQLQuery1.DataBase := ODBCConnection1;
     264    SQLQuery1.UsePrimaryKeyAsKey := False;
     265    SQLQuery1.SQL.Text := 'SELECT Acronym,Meaning FROM data1';
     266    SQLQuery1.Open;
     267
     268    NewAcronym := TAcronymEntry.Create;
     269    while not SQLQuery1.EOF do begin
     270      NewAcronym.Name := SQLQuery1.FieldByName('Acronym').AsString;
     271      NewAcronym.Meaning := SQLQuery1.FieldByName('Meaning').AsString;
     272      Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning);
     273      SQLQuery1.Next;
     274      Inc(ItemCount);
     275    end;
     276    NewAcronym.Free;
     277  finally
     278    SQLQuery1.Free;
     279    SQLTransaction1.Free;
     280    ODBCConnection1.Free;
     281  end;
     282end;
     283
    232284{ TImportPatterns }
    233285
     
    321373end;
    322374
     375procedure TImportSource.Process;
     376begin
     377  case Format.Kind of
     378    ifkParse: ProcessTextParse;
     379    ifkMSAccess: ProcessMSAccess;
     380    else raise Exception.Create('Unsupported import format');
     381  end;
     382end;
     383
    323384function StripHTML(S: string): string;
    324385var
     
    346407  I: Integer;
    347408begin
     409  Kind := Source.Kind;
    348410  Name := Source.Name;
    349411  Block.StartString := Source.Block.StartString;
     
    364426  WriteInteger(Node, 'Id', Id);
    365427  WriteString(Node, 'Name', Name);
     428  WriteInteger(Node, 'Kind', Integer(Kind));
    366429  WriteString(Node, 'BlockStartString', Block.StartString);
    367430  WriteString(Node, 'BlockEndString', Block.EndString);
     
    378441  Id := ReadInteger(Node, 'Id', 0);
    379442  Name := ReadString(Node, 'Name', '');
     443  Kind := TImportFormatKind(ReadInteger(Node, 'Kind', 0));
    380444  Block.StartString := ReadString(Node, 'BlockStartString', '');
    381445  Block.EndString := ReadString(Node, 'BlockEndString', '');
     
    513577{ TImportSource }
    514578
    515 procedure TImportSource.Process;
     579procedure TImportSource.ProcessTextParse;
    516580var
    517581  Stream: TMemoryStream;
Note: See TracChangeset for help on using the changeset viewer.