home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kompon / d123456 / ANRMLB.ZIP / component / mlbc.pas < prev   
Pascal/Delphi Source File  |  2001-09-27  |  15KB  |  608 lines

  1. unit mlbc;
  2.  
  3. interface
  4.  
  5. uses Forms, Classes, DsgnIntf, Dialogs, mlb2;
  6.  
  7. type
  8.   TMyStringProperty = class(TStringProperty)
  9.   public
  10.     procedure Edit; override;
  11.     function GetAttributes: TPropertyAttributes; override;
  12.   end;
  13.   TMlbc = class(TComponent)
  14.   private
  15.     _mlb: TMlb2;
  16.     _filename: TFileName;
  17.     FOnNotifyEvent: TNotifyEvent;
  18.     function ReadMlb: TMlb2;
  19.     function ReadCSVSeparator: string;
  20.     procedure WriteCSVSeparator(c: string);
  21.     function ReadQuoteSeparator: string;
  22.     procedure WriteQuoteSeparator(c: string);
  23.     function ReadDistinct: boolean;
  24.     procedure WriteDistinct(b: boolean);
  25.     function ReadBeginningOfFile: boolean;
  26.     procedure WriteBeginningOfFile(b: boolean);
  27.     function ReadEndOfFile: boolean;
  28.     procedure WriteEndOfFile(b: boolean);
  29.  
  30.     function ReadFileName: TFileName;
  31.     procedure WriteFileName(filename1: TFileName);
  32.  
  33.     function getName: string;
  34.     procedure setName(name1: string);
  35.     function FieldNameRead(index1: LongInt): string;
  36.     procedure FieldNameWrite(index1: LongInt; v: string);
  37.     function DataTypeRead(index1: LongInt): string;
  38.     procedure DataTypeWrite(index1: LongInt; v: string);
  39.     function AccessDataRead(field1, index1: LongInt): string;
  40.   protected
  41.   public
  42.     property Mlb: TMlb2 read ReadMlb;
  43.     Constructor Create(AOwner: TComponent); override;
  44.     Destructor Destroy; override;
  45.  
  46.     procedure Init;
  47.     procedure Clear;
  48.     procedure Assign(var mlb1: TMlb2);
  49.     function GetVersion: String;
  50.     function GetVersionNumber: Integer;
  51.     property Name: string read getName write setName;
  52.  
  53.     function AddField(fieldname1: string): Boolean;
  54.     function RemoveField(fieldname1: string): Boolean;
  55.     property FieldName[index1: LongInt]: string read FieldNameRead write FieldNameWrite;
  56.     property DataType[index1: LongInt]: string read DataTypeRead write DataTypeWrite;
  57.     function FieldCount: LongInt;
  58.  
  59.     procedure AddRow;
  60.     function InsertRow(where1: boolean): boolean;
  61.     function RemoveRow: Boolean;
  62.     function RemoveRowByIndex(k: LongInt): Boolean;
  63.     function CopyRow: boolean;
  64.     function PasteRow: boolean;
  65.     function CopyRowBySlot(slot: integer): boolean;
  66.     function PasteRowBySlot(slot: integer): boolean;
  67.  
  68.     function InitFieldWithData(fieldname1: string; data1: string): boolean;
  69.     function InitFieldWithValue(fieldname1: string; value1: Extended): boolean;
  70.     procedure ForceRows(nrows: LongInt);
  71.     function RowCount: LongInt;
  72.  
  73.     function GetCurrentRow: LongInt;
  74.     function IsEmpty: Boolean;
  75.  
  76.     function Go(row1: LongInt): Boolean;
  77.     function GoFirst: Boolean;
  78.     function GoLast: Boolean;
  79.     function GoNext: Boolean;
  80.     function GoPrevious: Boolean;
  81.     function BeginSeek(direction1: boolean): Boolean;
  82.     function EndSeek: Boolean;
  83.     function SeekData(fieldname1, comp1, value1: string): boolean;
  84.     function SeekFloat(fieldname1, comp1: string; value1: Extended): boolean;
  85.     function MatchData(fieldname1, comp1, value1: string): boolean;
  86.     function MatchFloat(fieldname1, comp1: string; value1: Extended): boolean;
  87.     function SavePosition: boolean;
  88.     function RestorePosition: boolean;
  89.     function GetPosition: LongInt;
  90.  
  91.     function GetData(fieldname1: string): string;
  92.     function SetData(fieldname1: string; data1: string): Boolean;
  93.     function GetDataByIndex(index1: LongInt): string;
  94.     function SetDataByIndex(index1: LongInt; data1: string): Boolean;
  95.     function GetFloat(fieldname1: string): Extended;
  96.     function SetFloat(fieldname1: string; float1: Extended): Boolean;
  97.     function GetFloatByIndex(index1: LongInt): Extended;
  98.     function SetFloatByIndex(index1: LongInt; float1: Extended): Boolean;
  99.     function GetFieldName(index1: LongInt): string;
  100.     function GetFieldIndex(fieldname1: string): LongInt;
  101.     property AccessData[field1, index1: LongInt]: string read AccessDataRead;
  102.  
  103.     function LoadFromFile(filename1: string): Boolean;
  104.     function LoadFromCSVFile(filename1: string): Boolean;
  105.     function LoadFromISAMFile(filename1: string): Boolean;
  106.     function LoadFromMLBFile(filename1: string): Boolean;
  107.  
  108.     function SaveCurrentFile: boolean;
  109.     function SaveToFile(FileName1: string): boolean;
  110.     function SaveToCSVFile(filename1: string): Boolean;
  111.     function SaveToISAMFile(filename1: string): Boolean;
  112.     function SaveToMLBFile(filename1: string): Boolean;
  113.     function SaveToExcelFile(FileName1: string): boolean;
  114.  
  115.     function RobustStrToFloat(s1: string): Extended;
  116.     function RobustFloatToStr(v1: Extended): string;
  117.     function SortByData(fieldname1: string; lowest2greatest1: boolean): boolean;
  118.     function SortByFloat(fieldname1: string; lowest2greatest1: boolean): boolean;
  119.     procedure RandomSort;
  120.     procedure MakeDistinct;
  121.     function AreSameRows(k, l: LongInt): boolean;
  122.     function Fusion(var dest_mlb, source_mlb: TMlb2; a1: TMlbFusionArray): boolean;
  123.   published
  124.     property CSVSeparator: string read ReadCSVSeparator write WriteCSVSeparator;
  125.     property Distinct: boolean read ReadDistinct write WriteDistinct;
  126.     property QuoteSeparator: string read ReadQuoteSeparator write WriteQuoteSeparator;
  127.     property BeginningOfFile: boolean read ReadBeginningOfFile write WriteBeginningOfFile;
  128.     property EndOfFile: boolean read ReadEndOfFile write WriteEndOfFile;
  129.  
  130.     property FileName: TFileName read ReadFileName write WriteFileName;
  131.   end;
  132.  
  133. procedure Register;
  134.  
  135. implementation
  136.  
  137. function TMyStringProperty.GetAttributes: TPropertyAttributes;
  138. begin
  139.   Result := [paMultiSelect, paDialog];
  140. end;
  141.  
  142. procedure TMyStringProperty.Edit;
  143. var
  144.   OpenDialog: TOpenDialog;
  145. begin
  146.   inherited Edit;
  147.   OpenDialog := TOpenDialog.Create(Application);
  148.   try
  149.     OpenDialog.Filter := 'MyLittleBase Files|*.csv;*.txt;*.mlb';
  150.     if OpenDialog.Execute then
  151.       SetStrValue(OpenDialog.FileName);
  152.   finally
  153.     OpenDialog.Free;
  154.   end;
  155. end;
  156.  
  157. Constructor TMlbc.Create(AOwner: TComponent);
  158. begin
  159.      inherited Create(AOwner);
  160.      _mlb := TMlb2.Create;
  161. end;
  162.  
  163. Destructor TMlbc.Destroy;
  164. begin
  165.      _mlb.Free;
  166.      inherited Destroy;
  167. end;
  168.  
  169. function TMlbc.ReadMlb: TMlb2;
  170. begin
  171.      Result := _mlb;
  172. end;
  173.  
  174. function TMlbc.ReadFileName: TFileName;
  175. begin
  176.      Result := _filename;
  177. end;
  178.  
  179. procedure TMlbc.WriteFileName(filename1: TFileName);
  180. begin
  181.      if filename1<>'' then begin
  182.         Mlb.LoadFromFile(filename1);
  183.      end;
  184.      _filename := filename1;
  185. end;
  186.  
  187. function TMlbc.ReadCSVSeparator: string;
  188. begin
  189.      Result := Mlb.CSVSeparator;
  190. end;
  191.  
  192. procedure TMlbc.WriteCSVSeparator(c: string);
  193. begin
  194.      Mlb.CSVSeparator := c;
  195. end;
  196.  
  197. function TMlbc.ReadQuoteSeparator: string;
  198. begin
  199.      Result := Mlb.QuoteSeparator;
  200. end;
  201.  
  202. procedure TMlbc.WriteQuoteSeparator(c: string);
  203. begin
  204.      Mlb.QuoteSeparator := c;
  205. end;
  206.  
  207. function TMlbc.ReadDistinct: boolean;
  208. begin
  209.      Result := Mlb.Distinct;
  210. end;
  211.  
  212. procedure TMlbc.WriteDistinct(b: boolean);
  213. begin
  214.      Mlb.Distinct := b;
  215. end;
  216.  
  217. function TMlbc.ReadBeginningOfFile: boolean;
  218. begin
  219.      Result := Mlb.BeginningOfFile;
  220. end;
  221.  
  222. procedure TMlbc.WriteBeginningOfFile(b: boolean);
  223. begin
  224.      Mlb.BeginningOfFile := b;
  225. end;
  226.  
  227. function TMlbc.ReadEndOfFile: boolean;
  228. begin
  229.      Result := Mlb.EndOfFile;
  230. end;
  231.  
  232. procedure TMlbc.WriteEndOfFile(b: boolean);
  233. begin
  234.      Mlb.EndOfFile := b;
  235. end;
  236.  
  237. procedure TMlbc.Init;
  238. begin
  239.      Mlb.Init;
  240. end;
  241.  
  242. procedure TMlbc.Clear;
  243. begin
  244.      Mlb.Clear;
  245. end;
  246.  
  247. procedure TMlbc.Assign(var mlb1: TMlb2);
  248. begin
  249.      Mlb.Assign(mlb1);
  250. end;
  251.  
  252. function TMlbc.GetVersion: String;
  253. begin
  254.      Result := Mlb.GetVersion;
  255. end;
  256.  
  257. function TMlbc.GetVersionNumber: Integer;
  258. begin
  259.      Result := Mlb.GetVersionNumber;
  260. end;
  261.  
  262. function TMlbc.getName: string;
  263. begin
  264.      Result := Mlb.Name;
  265. end;
  266.  
  267. procedure TMlbc.setName(name1: string);
  268. begin
  269.      Mlb.Name := name1;
  270. end;
  271.  
  272.  
  273. function TMlbc.AddField(fieldname1: string): Boolean;
  274. begin
  275.      Result := Mlb.AddField(fieldname1);
  276. end;
  277.  
  278. function TMlbc.RemoveField(fieldname1: string): Boolean;
  279. begin
  280.      Result := Mlb.RemoveField(fieldname1);
  281. end;
  282.  
  283. function TMlbc.FieldNameRead(index1: LongInt): string;
  284. begin
  285.      Result := Mlb.FieldName[index1];
  286. end;
  287.  
  288. procedure TMlbc.FieldNameWrite(index1: LongInt; v: string);
  289. begin
  290.      Mlb.FieldName[index1] := v;
  291. end;
  292.  
  293. function TMlbc.DataTypeRead(index1: LongInt): string;
  294. begin
  295.      Result := Mlb.DataType[index1];
  296. end;
  297.  
  298. procedure TMlbc.DataTypeWrite(index1: LongInt; v: string);
  299. begin
  300.      Mlb.DataType[index1] := v;
  301. end;
  302.  
  303. function TMlbc.AccessDataRead(field1, index1: LongInt): string;
  304. begin
  305.      Result := Mlb.AccessData[field1, index1];
  306. end;
  307.  
  308. function TMlbc.FieldCount: LongInt;
  309. begin
  310.      Result := Mlb.FieldCount;
  311. end;
  312.  
  313. procedure TMlbc.AddRow;
  314. begin
  315.      Mlb.AddRow;
  316. end;
  317.  
  318. function TMlbc.InsertRow(where1: boolean): boolean;
  319. begin
  320.      Result := Mlb.InsertRow(where1);
  321. end;
  322.  
  323. function TMlbc.RemoveRow: Boolean;
  324. begin
  325.      Result := Mlb.RemoveRow;
  326. end;
  327.  
  328. function TMlbc.RemoveRowByIndex(k: LongInt): Boolean;
  329. begin
  330.      Result := Mlb.RemoveRowByIndex(k);
  331. end;
  332.  
  333. function TMlbc.CopyRow: boolean;
  334. begin
  335.      Result := Mlb.CopyRow;
  336. end;
  337.  
  338. function TMlbc.PasteRow: boolean;
  339. begin
  340.      Result := Mlb.PasteRow;
  341. end;
  342.  
  343. function TMlbc.CopyRowBySlot(slot: integer): boolean;
  344. begin
  345.      Result := Mlb.CopyRowBySlot(slot);
  346. end;
  347.  
  348. function TMlbc.PasteRowBySlot(slot: integer): boolean;
  349. begin
  350.      Result := Mlb.PasteRowBySlot(slot);
  351. end;
  352.  
  353. function TMlbc.InitFieldWithData(fieldname1: string; data1: string): boolean;
  354. begin
  355.      Result := Mlb.InitFieldWithData(fieldname1, data1);
  356. end;
  357.  
  358. function TMlbc.InitFieldWithValue(fieldname1: string; value1: Extended): boolean;
  359. begin
  360.      Result := Mlb.InitFieldWithValue(fieldname1, value1);
  361. end;
  362.  
  363. procedure TMlbc.ForceRows(nrows: LongInt);
  364. begin
  365.      Mlb.ForceRows(nrows);
  366. end;
  367.  
  368. function TMlbc.RowCount: LongInt;
  369. begin
  370.      Result := Mlb.RowCount;
  371. end;
  372.  
  373.  
  374. function TMlbc.GetCurrentRow: LongInt;
  375. begin
  376.      Result := Mlb.GetCurrentRow;
  377. end;
  378.  
  379. function TMlbc.IsEmpty: Boolean;
  380. begin
  381.      Result := Mlb.IsEmpty;
  382. end;
  383.  
  384.  
  385. function TMlbc.Go(row1: LongInt): Boolean;
  386. begin
  387.      Result := Mlb.Go(row1);
  388. end;
  389.  
  390. function TMlbc.GoFirst: Boolean;
  391. begin
  392.      Result := Mlb.GoFirst;
  393. end;
  394.  
  395. function TMlbc.GoLast: Boolean;
  396. begin
  397.      Result := Mlb.GoLast;
  398. end;
  399.  
  400. function TMlbc.GoNext: Boolean;
  401. begin
  402.      Result := Mlb.GoNext;
  403. end;
  404.  
  405. function TMlbc.GoPrevious: Boolean;
  406. begin
  407.      Result := Mlb.GoPrevious;
  408. end;
  409.  
  410. function TMlbc.BeginSeek(direction1: boolean): Boolean;
  411. begin
  412.      Result := Mlb.BeginSeek(direction1);
  413. end;
  414.  
  415. function TMlbc.EndSeek: Boolean;
  416. begin
  417.      Result := Mlb.EndSeek;
  418. end;
  419.  
  420. function TMlbc.SeekData(fieldname1, comp1, value1: string): boolean;
  421. begin
  422.      Result := Mlb.SeekData(fieldname1, comp1, value1);
  423. end;
  424.  
  425. function TMlbc.SeekFloat(fieldname1, comp1: string; value1: Extended): boolean;
  426. begin
  427.      Result := Mlb.SeekFloat(fieldname1, comp1, value1);
  428. end;
  429.  
  430. function TMlbc.MatchData(fieldname1, comp1, value1: string): boolean;
  431. begin
  432.      Result := Mlb.MatchData(fieldname1, comp1, value1);
  433. end;
  434.  
  435. function TMlbc.MatchFloat(fieldname1, comp1: string; value1: Extended): boolean;
  436. begin
  437.      Result := Mlb.MatchFloat(fieldname1, comp1, value1);
  438. end;
  439.  
  440. function TMlbc.SavePosition: boolean;
  441. begin
  442.      Result := Mlb.SavePosition;
  443. end;
  444.  
  445. function TMlbc.RestorePosition: boolean;
  446. begin
  447.      Result := Mlb.RestorePosition;
  448. end;
  449.  
  450. function TMlbc.GetPosition: LongInt;
  451. begin
  452.      Result := Mlb.GetPosition;
  453. end;
  454.  
  455. function TMlbc.GetData(fieldname1: string): string;
  456. begin
  457.      Result := Mlb.GetData(fieldname1);
  458. end;
  459.  
  460. function TMlbc.SetData(fieldname1: string; data1: string): Boolean;
  461. begin
  462.      Result := Mlb.SetData(fieldname1, data1);
  463. end;
  464.  
  465. function TMlbc.GetDataByIndex(index1: LongInt): string;
  466. begin
  467.      Result := Mlb.GetDataByIndex(index1);
  468. end;
  469.  
  470. function TMlbc.SetDataByIndex(index1: LongInt; data1: string): Boolean;
  471. begin
  472.      Result := Mlb.SetDataByIndex(index1, data1);
  473. end;
  474.  
  475. function TMlbc.GetFloat(fieldname1: string): Extended;
  476. begin
  477.      Result := Mlb.GetFloat(fieldname1);
  478. end;
  479.  
  480. function TMlbc.SetFloat(fieldname1: string; float1: Extended): Boolean;
  481. begin
  482.      Result := Mlb.SetFloat(fieldname1, float1);
  483. end;
  484.  
  485. function TMlbc.GetFloatByIndex(index1: LongInt): Extended;
  486. begin
  487.      Result := Mlb.GetFloatByIndex(index1);
  488. end;
  489.  
  490. function TMlbc.SetFloatByIndex(index1: LongInt; float1: Extended): Boolean;
  491. begin
  492.      Result := Mlb.SetFloatByIndex(index1, float1);
  493. end;
  494.  
  495. function TMlbc.GetFieldName(index1: LongInt): string;
  496. begin
  497.      Result := Mlb.GetFieldName(index1);
  498. end;
  499.  
  500. function TMlbc.GetFieldIndex(fieldname1: string): LongInt;
  501. begin
  502.      Result := Mlb.GetFieldIndex(fieldname1);
  503. end;
  504.  
  505. function TMlbc.LoadFromFile(filename1: string): Boolean;
  506. begin
  507.      Result := Mlb.LoadFromFile(filename1);
  508. end;
  509.  
  510. function TMlbc.LoadFromCSVFile(filename1: string): Boolean;
  511. begin
  512.      Result := Mlb.LoadFromCSVFile(filename1);
  513. end;
  514.  
  515. function TMlbc.LoadFromISAMFile(filename1: string): Boolean;
  516. begin
  517.      Result := Mlb.LoadFromISAMFile(filename1);
  518. end;
  519.  
  520. function TMlbc.LoadFromMLBFile(filename1: string): Boolean;
  521. begin
  522.      Result := Mlb.LoadFromMLBFile(filename1);
  523. end;
  524.  
  525. function TMlbc.SaveToFile(FileName1: string): boolean;
  526. begin
  527.      Result := Mlb.SaveToFile(filename1);
  528. end;
  529.  
  530. function TMlbc.SaveToCSVFile(filename1: string): Boolean;
  531. begin
  532.      Result := Mlb.SaveToCSVFile(filename1);
  533. end;
  534.  
  535. function TMlbc.SaveToISAMFile(filename1: string): Boolean;
  536. begin
  537.      Result := Mlb.SaveToISAMFile(filename1);
  538. end;
  539.  
  540. function TMlbc.SaveToMLBFile(filename1: string): Boolean;
  541. begin
  542.      Result := Mlb.SaveToMLBFile(filename1);
  543. end;
  544.  
  545. function TMlbc.SaveToExcelFile(FileName1: string): boolean;
  546. begin
  547.      Result := Mlb.SaveToExcelFile(filename1);
  548. end;
  549.  
  550.  
  551. function TMlbc.RobustStrToFloat(s1: string): Extended;
  552. begin
  553.      Result := Mlb.RobustStrToFloat(s1);
  554. end;
  555.  
  556. function TMlbc.RobustFloatToStr(v1: Extended): string;
  557. begin
  558.      Result := Mlb.RobustFloatToStr(v1);
  559. end;
  560.  
  561. function TMlbc.SortByData(fieldname1: string; lowest2greatest1: boolean): boolean;
  562. begin
  563.      Result := Mlb.SortByData(fieldname1, lowest2greatest1);
  564. end;
  565.  
  566. function TMlbc.SortByFloat(fieldname1: string; lowest2greatest1: boolean): boolean;
  567. begin
  568.      Result := Mlb.SortByFloat(fieldname1, lowest2greatest1);
  569. end;
  570.  
  571. procedure TMlbc.RandomSort;
  572. begin
  573.      Mlb.RandomSort;
  574. end;
  575.  
  576. procedure TMlbc.MakeDistinct;
  577. begin
  578.      Mlb.MakeDistinct;
  579. end;
  580.  
  581. function TMlbc.AreSameRows(k, l: LongInt): boolean;
  582. begin
  583.      Result := Mlb.AreSameRows(k, l);
  584. end;
  585.  
  586. function TMlbc.Fusion(var dest_mlb, source_mlb: TMlb2; a1: TMlbFusionArray): boolean;
  587. begin
  588.      Result := Mlb.Fusion(dest_mlb, source_mlb, a1);
  589. end;
  590.  
  591. function TMlbc.SaveCurrentFile: boolean;
  592. begin
  593.      if _filename<>'' then begin
  594.          Result := SaveToFile(_filename);
  595.      end else begin
  596.          Result := false;
  597.      end;
  598. end;
  599.  
  600. procedure Register;
  601. begin
  602.   RegisterPropertyEditor(TypeInfo(TFileName), nil, 'FileName', TMyStringProperty);
  603.   RegisterComponents('Mlb', [TMlbc]);
  604. end;
  605.  
  606. end.
  607.  
  608.