home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kompon / d3456 / ACF10CE.ZIP / NyBck.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  20.9 KB  |  680 lines

  1. //TNyBck compenent V 1.3  10.9.2001
  2. //Nihat Yorganc² nyorganci@hotmail.com
  3. // Please send me notes, bugs and problems
  4.  
  5.  
  6. //export and import whole database to the text files and binary files.
  7. // Memo and BLOB fields are also supported. TnyBck is saved Total record count in Text file when Export.
  8. //so you can use this count as Gauge Max Value.Please examine to Demo.
  9. //You don't have to export calculated field or lookupfields with Tnybck.
  10.  
  11. //if you have calculated fields or lookupfields in dataset you must not be
  12. // export this fields. See Csvmap properties.
  13.  
  14. // You can use this component for free in commercial or non-commercial programs
  15. // Please send me the changes you made in source code, and do not forgret my credit!
  16. // Read Readme.txt file included with the package for help and credits.
  17.  
  18. //This compenent TPgCSV (Khashayar Sadjadi (khashi@pragena.8m.com)) And KDatabase Export pack(delphi@korzh.com) Combined.
  19.  
  20.  
  21. //Installation:
  22.  
  23. // Remove Nybck component previous version.Click Component menu. Select Install Component.
  24. //Select Nybck.pas in Unit File Name with Browse.
  25. //Select Package file name exist your computer(*.dpk).
  26. //or Select into new package, write a new filename in Package file name.Press ok.
  27. //Appear package box and press install. After Save *.dpk file.
  28.  
  29.  
  30.  
  31. //Usage
  32. // 1. Place the component of your Form or DataModule.
  33. // 2. Set the proprties (See properties section in this readme)
  34. // 3. Close dataset
  35. // 4. Call Imprt or Exprt methods.
  36. // 5. Open Dataset
  37.  
  38. //Properties:
  39.  
  40. //CSVMap : Mapping of BCK file(text file) and table fields. A List of field names, started bt value of
  41. //      FieldIndicator value and seprated by Seprator value.
  42. //           Ex: $Name,$Age,$BirthDate
  43. //           if you writed CSVMap and Export all records, please don't change
  44. //           CSVMap string while import all records to dataset. Othervise raised errors.
  45. //           only exported and imported fields in CsvMap string. So you don't have to Export
  46. //calculated and lookup fields.
  47.  
  48.  
  49. // Dataset :Tdataset. TDataset in Delphi forms or DataModules to link with TNyBck for Import and Export.
  50.  
  51. //Delimiter: Char. Seprator character.specifies the delimiter that will separate field values in
  52. // the text files.Default '"' .
  53.  
  54. //FieldIndicator  : Special character for identifing field names in CSVMap.
  55.  
  56. //Seprator    : Seprator character. Offten ,
  57.  
  58. //SilentImport    :boolean. Setting this property to True forces TNyBck to do not raise exceptions and call ImportError event
  59.  
  60.  
  61. //TextFile :String. A Text file. Each record in a seperate line, seperated by CR.
  62. //          if your have blob or memo field TnyBck create a binary file (*.mem).
  63. //example: textfile:= 'myfile.Bck', TnyBck also create myfile.mem.
  64.  
  65.  
  66. //TotalRecord :integer.Read only. Get Totol record  in BeforeExport and Before▌mport events.You get Total Record only this two events.
  67.               // You can use Totol Record your gauge max value.
  68. //Events:
  69.  
  70. //AfterCloseTable  : Fires after TNyBck closed dataset.
  71.  
  72. //AfterExport      : Fires after export process of a dataset to a Text Files( and *.Mem files) finishes.
  73.  
  74. //AfterImport     : Fires after import process of a Text files (and *.mem) to dataset finishes.
  75.  
  76. //AfterOpenTable   : Fires after TNyBck opens the dataset.
  77.  
  78. //BeforeCloseTable : Fires before TNyBck closes the database.
  79.  
  80. //BeforeExport     : Fires before export process starts from a Dataset to a Text files.
  81.  
  82. //BeforeImport     : Fires before import process starts from a Text files to a Dataset.
  83.  
  84. //BeforeOpenTable  : Fires before TNyBck opens dataset.
  85.  
  86. //ImportError     : Firest each time an exception occures in Importing a Text to a dataset.
  87. //           You can force TNyBck to handle ignore error or abort the process.
  88. //           This event will be fired only if Silent²mport property is setted to True.
  89.  
  90. //ExportProgress     : Fires each time a new record added to a Text files during exportin a dataset to a textFiles.
  91. //           You can Stop export progress by setting StopIt parameter to True.
  92.  
  93. //ImportProgress     : Fires each time a new record added to a dataset during importing a text fileto a dataset.
  94. //           You can Stop import progress by setting StopIt parameter to True.
  95.  
  96. //OnAddRecord     : Fires each time a new record added to dataset during importing a Text to a dataset.
  97. //Exception handling:
  98.  
  99. //By setting SilentImport property to True, if an exception occure in Import method, TNyBck will
  100. //not raise exception and will call ImportError event with exception message and record number.
  101. //You can set the Response parameter to nybckIgnore or nybckAbort to make TnyBck handle the exception.
  102. //Setting Response to nybckIgnore will make TNyBck ignore current record and it will continue Importing, but
  103. //nybckAbort will terminate import process at the currect record.
  104. //Default value of Response parameter is nybckIgnore.
  105.  
  106. //Progress monitoring:
  107.  
  108. //By writing event handlers for ExportProgress and ImportProgress events, you can monitor Import and/or
  109. //Export progress during the process. You can also stop process by setting StopIt parameter to True within
  110. //event handler.
  111.  
  112. //Total Record: Readonly.Total record write in text file first line(Export method).
  113. //              Total Record Reading in text file first line(Import mehthod).
  114. //You can get Total record in BeforeExport and BeforeImport events.
  115.  
  116. //AutoMapping feature:
  117. //----------------------------------------------
  118. //If you leave the CSVMap property blank, TPgCSV will use all Dataset
  119. // fields to generate *.Bck file in Exprt and ▌mprt method.
  120.  
  121.  
  122. //History:
  123.  
  124. ///ver 1.3. (10.9.2001)
  125. //a major bug solved in imprt method.
  126.  
  127. //ver 1.2. (8.9.2001)
  128. //Export Method change Exprt, ▌mport Method change imprt.
  129. //CsvMap, fieldindicator and Seprator properties added.
  130.  
  131. //ver 1.1   (26.1.2001)
  132. //Some bugs solved.
  133.  
  134. unit NyBck;
  135.  
  136. interface
  137.  
  138. uses
  139.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  140.   Db;
  141.   type
  142.   TNyError = class(Exception)  //Pgcsv hav'not.
  143.   end;
  144.  
  145.  
  146. type
  147.  
  148.    TNyBckErrorResponse     = (nybckAbort, nybckIgnore);
  149.  
  150.   TNyBckProgressEvent     = procedure (Sender : TObject; AProgress: LongInt; var StopIt: Boolean) of object;
  151.   TNyBckImportErrorEvent  = procedure (Sender : TObject; Mess: string; RecNo: LongInt; var Response:TNyBckErrorResponse) of object;
  152.  
  153.  
  154.   TNyBck = class(TComponent)
  155.   private
  156.     { Private declarations }
  157.     FDataset         : TDataset;
  158.      FTextFile       :string;
  159.       FCSVMap        :string;
  160.      FDelimiter      :char;
  161.      FSilentImport   :Boolean;
  162.      Fstop           :Boolean;
  163.      Ftotal          :longint;//totalrec.
  164.      FSeprator,FFieldIndicator  : Char;
  165.       FMapItems:integer;
  166.  
  167.      FBeforeOpenTable,
  168.    FAfterOpenTable,
  169.    FBeforeCloseTable,
  170.    FAfterCloseTable,
  171.  
  172.    FBeforeExport,
  173.    FAfterExport,
  174.    FBeforeImport,
  175.    FAfterImport,
  176.    FOnAddRecord     : TNotifyEvent;
  177.    FExportProgress,
  178.    FImportProgress  : TNyBckprogressEvent;
  179.    FImportError     : TNyBckImportErrorEvent;
  180.     FFieldCache      : TList;
  181.   protected
  182.     { Protected declarations }
  183.  
  184.  
  185.      procedure ClearFileExt(var FileName : string);
  186.      procedure ChangeFileExtt(var FileName : string; const NewExt :string);
  187.     // function FixPath(const Path : string) : string;
  188.      function DelimitedText(Strings : TStrings; Delimiter, Quote : char) : string;
  189.      function QuotedString(const S : string; Quote : char) : string;
  190.      //Yedekal ba■l²yor.
  191.  
  192.      procedure ComposeText(const S : string; Delimiter, Quote : char; Strings : TStrings);
  193.      function UnquotedString(const S : string; Quote : char) : string;
  194.      function CountMapItems:Integer;
  195.      function WordCount(const S ,WordDelim: string): Integer;
  196.      function GetMapItem(ItemIndex:Integer;var AField:Boolean):string;
  197.      function ExtractWord(Item: Integer;S, WordDelim: string): string;
  198.      function WordPosition(Item: Integer; const S, SubStr: string): Integer;
  199.      function BuildMap:string;//Csvmap bo■sa tⁿm alanlar² dahil et.
  200.   public
  201.     { Public declarations }
  202.     constructor Create(AOwner: TComponent); override;
  203.     destructor Destroy;override;
  204.   published
  205.     { Published declarations }
  206.      //properties
  207.    Property TotalRecord      :longint                 read Ftotal;
  208.    property Dataset          : TDataset               read FDataset          write FDataset;
  209.    property TextFile          : string                 read FTextFile          write FTextFile;
  210.    property Delimiter        : Char                   read FDelimiter        write FDelimiter;
  211.    property SilentImport     : Boolean                read FSilentImport     write FSilentImport;
  212.    property FieldIndicator   : Char                   read FFieldIndicator   write FFieldIndicator;
  213.    property Seprator         : Char                   read FSeprator         write FSeprator;
  214.    property CSVMap           : string                 read FCSVMap           write FCSVMap;
  215.  
  216.     //events
  217.    property BeforeOpenTable  : TNotifyEvent           read FBeforeOpenTable  write FBeforeOpenTable;
  218.    property AfterOpenTable   : TNotifyEvent           read FAfterOpenTable   write FAfterOpenTable;
  219.    property BeforeCloseTable : TNotifyEvent           read FBeforeCloseTable write FBeforeCloseTable;
  220.    property AfterCloseTable  : TNotifyEvent           read FAfterCloseTable  write FAfterCloseTable;
  221.  
  222.    property BeforeImport     : TNotifyEvent           read FBeforeImport     write FBeforeImport;
  223.    property AfterImport      : TNotifyEvent           read FAfterImport      write FAfterImport;
  224.    property BeforeExport     : TNotifyEvent           read FBeforeExport     write FBeforeExport;
  225.    property AfterExport      : TNotifyEvent           read FAfterExport      write FAfterExport;
  226.    property ExportProgress   : TNyBckProgressEvent    read FExportProgress   write FExportProgress;
  227.    property ImportProgress   : TNyBckProgressEvent    read FImportProgress   write FImportProgress;
  228.    property OnAddRecord      : TNotifyEvent           read FOnAddRecord      write FOnAddRecord;
  229.    property ImportError      : TNyBckImportErrorEvent read FImportError      write FImportError;
  230.    //methodes
  231.    procedure Exprt;//DatasetToText;
  232.    procedure Imprt;//TextToDataset;
  233.  
  234.   end;
  235.  
  236. procedure Register;
  237.  
  238. implementation
  239. procedure Tnybck.Exprt;//DatasetToText
  240. var
  241. D : string;
  242. B : Boolean;
  243. i : integer;
  244. C : LongInt;//progresin say²s²n² tutar.
  245.  
  246.   slOut, slRow : TStrings;
  247.   MS1, MS2 : TMemoryStream;
  248.  
  249. begin
  250.  if FTextFile='' then
  251.       raise TNyError.Create('NyBck Error: Please write backup Text file name.');
  252.  
  253.      if FDataSet = nil then
  254.     raise TNyError.Create('NyBck Error : Dataset is not specified');
  255.  
  256.       if Assigned(FBeforeOpenTable) then
  257.     FBeforeOpenTable(Self);
  258.  
  259.      Fdataset.open;
  260.     if Assigned(FAfterOpenTable) then
  261.     FAfterOpenTable(Self);
  262.  
  263.  
  264.     try  //transfer start
  265.  
  266.  
  267.       slOut := TStringList.Create;
  268.   slRow := TStringList.Create;
  269.   MS1 := TMemoryStream.Create;
  270.   MS2 := TMemoryStream.Create;
  271.  
  272.   //create field cache
  273.  FFieldCache:=TList.Create;
  274.  
  275.   FMapItems:=0;
  276.  // filename:=dosyaadi;
  277.   try
  278.  
  279.   C:=0;//▌lerleme miktar²
  280.     FDataSet.First;
  281.     if Trim(FCSVMap) = '' then
  282.   FCSVMap:=BuildMap;
  283.  
  284.     FDataset.DisableControls;//ekran kompenentleri pasif
  285.      slRow.Clear;
  286.       Ftotal:=Fdataset.RecordCount;
  287.        slRow.Add(inttostr(Ftotal)); //toplam rekordu kaydet
  288.         slOut.Add(DelimitedText(slRow, Fseprator,FDelimiter));// '"'));
  289.      if Assigned(FBeforeExport) then
  290.   FBeforeExport(Self);
  291.     while (not FDataset.Eof) and (not FStop) do//not FDataSet.EOF do
  292.     begin
  293.       slRow.Clear;
  294.       for  i:=1 to CountMapItems do//i := 0 to FDataSet.FieldCount - 1 do
  295.       begin
  296.        D:=GetMapItem(i,B);
  297.        if B=false then //wrong field defination.
  298.         raise TNyError.Create('NyBck Error : '+D+' is not a Field Defination for CSVmap Strings.Fieldindicator is wrong.');
  299.  
  300.  
  301.        if not (FDataSet.FieldByName(D).DataType in [ftBlob, ftMemo, ftGraphic, ftFmtMemo,
  302.                                               ftParadoxOle, ftDBaseOle, ftTypedBinary]) then
  303.  
  304.  
  305.          slRow.Add(FDataSet.FieldByName(D).AsString)
  306.         else begin
  307.           MS2.Clear;
  308.           (FDataSet.FieldByName(D) as TBlobField).SaveToStream(MS2);
  309.           MS1.CopyFrom(MS2,0);
  310.           slRow.Add(IntToStr(MS2.Size));
  311.         end;
  312.       end;
  313.       slOut.Add(DelimitedText(slRow,Fseprator,FDelimiter));// '"'));
  314.  
  315.       FDataSet.Next;
  316.       if Assigned(FExportProgress) then
  317.     FExportProgress(Self, C, FStop);
  318.        Inc(C);//ilerleme miktar².
  319.     end; //ⁿsttej■ while not fdatasete gidiyor.
  320.      if ExtractFileExt(FtextFile) = '' then FtextFile := FtextFile + '.txt';
  321.     slOut.SaveToFile(FtextFile);
  322.  
  323.  if MS1.Size > 0 then
  324.     begin
  325.       ChangeFileExtt(FTextFile, 'mem');
  326.       MS1.SaveToFile(FtextFile);
  327.     end;
  328.   finally
  329.     slRow.Free;
  330.     slOut.Free;
  331.     MS2.Free;
  332.     MS1.Free;
  333.     FFieldCache.Free;
  334.     FDataset.EnableControls;
  335.      if Assigned(FAfterExport) then
  336.   FAfterExport(Self);
  337.    end;
  338.    finally
  339.      if Assigned(FBeforeCloseTable) then
  340.     FBeforeCloseTable(Self);
  341.       Fdataset.Close;
  342.       if Assigned(FAfterCloseTable) then
  343.     FAfterCloseTable(Self);
  344.     end;
  345.  
  346.  
  347. end;
  348.  
  349. procedure TNyBck.imprt;//TextToDataset;
  350. var                  //CsvToDataset
  351.   i,j : integer;
  352.   D : string;
  353.   B:boolean;
  354.   slIn, slValues : TStrings;
  355.   MS1, MS2 : TMemoryStream;
  356.   sz : integer;
  357.  
  358.   memdosya:string;
  359.    ErrorResponse : TNyBckErrorResponse ;
  360.    C : LongInt;//progresin say²s²n² tutar.
  361.    //CoNoexp:longint;//Key violation hatas² nedeniyle kayda girmeyen kay²tlar.
  362. begin //g
  363.  
  364.   if FTextFile='' then
  365.       raise TNyError.Create('NyBck Error: Please write backup Text file name.');
  366.  
  367.  
  368.    if FDataSet = nil then
  369.     raise TNyError.Create('NyBck Error : Dataset is not specified');
  370.  
  371.   slIn := TStringList.Create;
  372.   slValues := TStringList.Create;
  373.   MS1 := TMemoryStream.Create;
  374.   MS2 := TMemoryStream.Create;
  375.    //create field cache
  376.  FFieldCache:=TList.Create;
  377.  //initiate map items
  378.  FMapItems:=0;
  379.  
  380.       try //e
  381.       if Assigned(FBeforeOpenTable) then
  382.     FBeforeOpenTable(Self);
  383.  
  384.      Fdataset.Open;
  385.      if Assigned(FAfterOpenTable) then
  386.     FAfterOpenTable(Self);
  387.     MS1.Position := 0;
  388.      FDataset.DisableControls;//ekran kompenentleri pasif
  389.      C:=0;//▌lerleme miktar²
  390.  
  391.     Memdosya:=FTextFile;
  392.     ClearFileExt(memdosya);
  393.     slIn.LoadFromFile(FTextFile);
  394.     if FileExists(MemDosya + '.mem') then
  395.       MS1.LoadFromFile(MemDosya + '.mem');
  396.  
  397.     ComposeText(slIn[0],FSeprator, FDelimiter, slValues);//kay²t toplam²n² al.
  398.       Ftotal:=strtoint(slValues[0]);//toplam kayd² integer olarak al.
  399.     //memolar² ilk Ms1 e yⁿkle.
  400.          //export to table from text file
  401.  if Assigned(FBeforeImport) then
  402.   FBeforeImport(Self);
  403.     if Trim(FCSVMap) = '' then
  404.   FCSVMap:=BuildMap;
  405.  
  406.     for i := 1 to slIn.Count - 1 do //0 to idi ama ilk kay²t toplam kay²t adedi oldu≡undan.
  407.     begin  //d
  408.  
  409.     if FStop=true then break;
  410.            try//h
  411.       Fdataset.Append;
  412.       ComposeText(slIn[i], FSeprator,FDelimiter, slValues);
  413.       for j := 0 to slValues.Count - 1 do
  414.       begin //c
  415.       d:=getmapitem(j+1,B);
  416.       if B=false then //wrong field defination.
  417.         raise TNyError.Create('NyBck Error : '+D+' is not a Field Defination for CSVmap Strings.Fieldindicator is wrong.');
  418.  
  419.  
  420.         if not (Fdataset.Fieldbyname(D).DataType in [ftBlob, ftMemo, ftGraphic, ftFmtMemo,
  421.                                               ftParadoxOle, ftDBaseOle, ftTypedBinary]) then
  422.           Fdataset.Fieldbyname(D).AsString := slValues[j]
  423.         else begin//b
  424.           sz := StrToInt(slValues[j]);
  425.           if sz > 0 then
  426.           begin //a
  427.             MS2.CopyFrom(MS1,sz);
  428.             MS2.Position := 0;
  429.             (Fdataset.Fieldbyname(D) as TBlobField).LoadFromStream(MS2);
  430.             MS2.Clear;
  431.           end; //a
  432.         end;//b
  433.       end; //c
  434.       Fdataset.Post;
  435.       except
  436.       on E:Exception do
  437.      if not FSilentImport then
  438.       raise
  439.      else
  440.      if Assigned(FImportError) then
  441.        begin
  442.         FImportError(Self,E.Message,C,ErrorResponse);
  443.         if ErrorResponse = NyBckAbort then
  444.          Break;
  445.        end;
  446.  
  447.       end;//h
  448.       if Assigned(FOnAddRecord) then
  449.     FOnAddRecord(Self);
  450.    if Assigned(FImportProgress) then
  451.     FImportProgress(Self, C, FStop);
  452.    Inc(C);
  453.      end;//d
  454.       //Inc(Coexp);//ilerleme miktar².//key violation hatas² olsa bile buraya u≡ruyor.
  455.  
  456.  
  457.     FDataset.EnableControls;//ekran kompenentleri aktif.dikkat alttaki fdataset.active=false'den ÷nce gelmeli yoksa hata veriyor.
  458.     if Assigned(FAfterImport) then
  459.   FAfterImport(Self);
  460.  
  461.     Fdataset.close;
  462.  
  463.       if Assigned(FAfterCloseTable) then
  464.     FAfterCloseTable(Self);
  465.  
  466.   finally
  467.     MS1.Free;
  468.     MS2.Free;
  469.     slValues.Free;
  470.     slIn.Free;
  471.     FFieldCache.Free;
  472.   end;//e
  473.  
  474. end; //g
  475.  
  476.  
  477.  
  478. procedure TNyBck.ComposeText(const S : string; Delimiter, Quote : char; Strings : TStrings);
  479. var
  480.   i, prev : integer;
  481.   b : boolean;
  482. begin
  483.   prev := 0;
  484.   b := false;
  485.   Strings.Clear;
  486.   for i := 1 to Length(S) do
  487.   begin
  488.     if S[i] = Quote then b := not b;
  489.     if not b and (S[i] = Delimiter) then
  490.     begin
  491.      Strings.Add(UnquotedString(Trim(Copy(S, prev + 1, i - prev - 1)), Quote));
  492.       prev := i;
  493.  
  494.     end;
  495.   end;
  496.  Strings.Add(UnquotedString(Trim(Copy(S, prev + 1, Length(S))), Quote));
  497. end;
  498.  
  499. //return unquoted string
  500. function TNyBck.UnquotedString(const S : string; Quote : char) : string;
  501. var
  502.   i : integer;
  503. begin
  504.   if (S = '') or (S[1] <> Quote) then
  505.   begin
  506.     Result := S;
  507.     exit;
  508.   end;
  509.   Result := ''; i := 2;
  510.   while i < Length(S) do
  511.   begin
  512.     if S[i] = Quote then
  513.     begin
  514.       if S[i + 1] = Quote then
  515.       begin
  516.         Result := Result + Quote;
  517.         inc(i, 2);
  518.         continue;
  519.       end;
  520.     end;
  521.     Result := Result + S[i];
  522.     inc(i);
  523.   end;
  524. end;
  525.  
  526.  
  527.  
  528. procedure TNyBck.ClearFileExt(var FileName : string);
  529. var
  530.   p : integer;
  531. begin
  532.   p := Length(FileName);
  533.   while (p > 0) and (FileName[p] <> '.') do dec(p);
  534.   if p = 0 then exit;
  535.   Delete(FileName, p, Length(FileName));
  536.  
  537. end;
  538.  
  539. procedure TNyBck.ChangeFileExtt(var FileName : string; const NewExt :string);
  540. begin
  541.   ClearFileExt(FileName);
  542.   FileName := FileName + '.' + NewExt;
  543. end;
  544.  
  545.  
  546. function TNyBck.DelimitedText(Strings : TStrings; Delimiter, Quote : char) : string;
  547. var
  548.   i : integer;
  549. begin
  550.   Result := '';
  551.   for i := 0 to Strings.Count - 1 do
  552.   begin
  553.     if i <> 0 then Result := Result + Delimiter;
  554.     Result := Result + QuotedString(Strings[i], Quote);
  555.   end;
  556. end;
  557. function TNyBck.QuotedString(const S : string; Quote : char) : string;
  558. var
  559.   i : integer;
  560. begin
  561.   Result := Quote;
  562.   for i := 1 to Length(S) do
  563.   begin
  564.     Result := Result + S[i];
  565.     if S[i] = Quote then
  566.       Result := Result + Quote;
  567.   end;
  568.   Result := Result + Quote;
  569. end;
  570.  
  571.  
  572. function TNyBck.CountMapItems:Integer;
  573. begin
  574.  if FMapItems = 0 then
  575.   FMapItems:=WordCount(FCSVMap,FSeprator);
  576.  Result:=FMapItems;
  577. end;
  578. function TNYBck.WordCount(const S ,WordDelim: string): Integer;
  579. var
  580.  i,
  581.  Count :Integer;
  582. begin
  583.  Count:=0;
  584.  for i:=1 to Length(S) do
  585.   if Copy(S,i,Length(WordDelim)) = WordDelim then
  586.    Inc(Count);
  587.  Result:=Count + 1;
  588. end;
  589. function TNYBck.GetMapItem(ItemIndex:Integer;var AField:Boolean):string;
  590. var
  591.  S : string;
  592.  P : ^ShortString;
  593. begin
  594.  if FFieldCache.Count < ItemIndex then
  595.   begin
  596.    S:=ExtractWord(ItemIndex,FCSVMap,FSeprator);
  597.    New(P);
  598.    P^:=S;
  599.    FFieldCache.Add(P);
  600.   end
  601.  else
  602.   S:=ShortString(FFieldCache.Items[ItemIndex - 1]^);
  603.  AField:=True;
  604.  if (Length(S) >= 1) and (S[1] = FFieldIndicator) then
  605.   Result:=Copy(S,2,Length(S) - 1)
  606.  else
  607.   begin
  608.    AField:=False;
  609.    Result:=S;
  610.   end;
  611. end;
  612.  
  613. function TNYBck.ExtractWord(Item: Integer;S, WordDelim: string): string;
  614. var
  615.  First,
  616.  Second:Integer;
  617. begin
  618.  First:=WordPosition(Item - 1,S,WordDelim);
  619.  Second:=WordPosition(Item,S,WordDelim);
  620.  if Second = 0 then
  621.   Second:=Length(S) + Length(WordDelim);
  622.  if First = 1 then
  623.   First:=-Length(WordDelim);
  624.  Result:=Copy(S,First + Length(WordDelim),Second - (First + Length(WordDelim)));
  625.  if Item = 1 then
  626.   Delete(Result,Length(Result),1);
  627. end;
  628.  
  629. function TNYBck.WordPosition(Item: Integer; const S, SubStr: string): Integer;
  630. var
  631.  i,
  632.  Count : Integer;
  633. begin
  634.  Count:=0;
  635.  Result:=0;
  636.  for i:=1 to Length(S) do
  637.   begin
  638.    if Copy(S,i,Length(SubStr)) = SubStr then
  639.     Inc(Count);
  640.    if Count = Item then
  641.     begin
  642.      Result:=i;
  643.      Break;
  644.     end;
  645.   end;
  646. end;
  647. function TNYBck.BuildMap:string;
  648. var
  649.  i:Integer;
  650.  S:string;
  651. begin
  652.  S:='';
  653.  for i:=0 to FDataset.FieldCount - 1 do
  654.   S:=S + FFieldIndicator + FDataset.Fields[i].FieldName + FSeprator;
  655.  Delete(S,Length(S),1);//Em sondaki Fseprat÷rⁿ siliyor.
  656.  Result:=S;
  657. end;
  658.  
  659. constructor TNyBck.Create(AOwner: TComponent);
  660. begin
  661.  inherited Create(AOwner);
  662.  FDelimiter:='"';
  663.  FFieldIndicator:='$';
  664.  FSeprator:=',';
  665.  FSilentImport:=True;
  666.  FStop:=False;
  667. end;
  668. destructor TNyBck.Destroy;
  669. begin
  670.   inherited;
  671. end;
  672.  
  673.  
  674. procedure Register;
  675. begin
  676.   RegisterComponents('Nihat', [TNyBck]);
  677. end;
  678.  
  679. end.
  680.