Советы по Delphi


Импорт CSV ASCII


...вот то, что вам нужно. Я использую этот компонент для работы с разделителем при импорте ASCII.

Dave

unit Cdbascii;

interface

uses

SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs, DbiErrs, DbiTypes, DbiProcs, DB, DBTables;
type
TAsciiDelimTable = class(TTable)private{ Private declarations }fQuote :Char;fDelim :Char;protected{ Protected declarations }function CreateHandle: HDBICur; override;Procedure SetQuote(newValue :Char);Procedure SetDelim(newValue :Char);public{ Public declarations }constructor Create(AOwner: TComponent); override;destructor Destroy; override;{ Эти свойства не должны больше публиковаться }property IndexFieldNames;property IndexName;property MasterFields;property MasterSource;property UpdateMode;published{ Published declarations }Property Quote:Char Read fQuote Write setQuote Default '"';Property Delim:Char Read fDelim Write setDelim Default ',';end;
procedure Register;

implementation

uses
DBConsts;

procedure Register;
begin
RegisterComponents('Data Access', [TAsciiDelimTable]);end;

constructor TAsciiDelimTable.Create(AOwner: TComponent);
Begin
Inherited
Create(AOwner);Exclusive:=True;TableType:=ttASCII;fQuote := '"';fDelim := ',';End;

destructor TAsciiDelimTable.Destroy;
Begin
Inherited
Destroy;End;

{ Рабочий код }

function CheckOpen(Status: DBIResult): Boolean;
begin
case
Status ofDBIERR_NONE:Result := True;DBIERR_NOTSUFFTABLERIGHTS:beginif not Session.GetPassword then DbiError(Status);Result := False;end;elseDbiError(Status);end;end;

function TAsciiDelimTable.CreateHandle: HDBICur;
const
OpenModes: array[Boolean] of DbiOpenMode = (dbiReadWrite, dbiReadOnly);ShareModes: array[Boolean] of DbiShareMode = (dbiOpenShared, dbiOpenExcl);var
STableName: array[0..SizeOf(TFileName) - 1] of Char;SDriverType: array[0..12] of Char;begin
if TableName = '' then DBError(SNoTableName);AnsiToNative(DBLocale, TableName, STableName, SizeOf(STableName) - 1);StrPCopy(SDriverType, 'ASCIIDRV-'+Quote+'-'+Delim);Result := nil;while not CheckOpen(DbiOpenTable(DBHandle, STableName, SDriverType,nil, nil, 0, OpenModes[ReadOnly], ShareModes[Exclusive],xltField, False, nil, Result)) do {Повтор};end;

Procedure TAsciiDelimTable.SetQuote(newValue :Char);
Begin
If
Active Then{ DBError(SInvalidBatchMove); };fQuote := newValue;End;
Procedure TAsciiDelimTable.SetDelim(newValue :Char);
Begin
If
Active Then{ DBError(SInvalidBatchMove); };fDelim := newValue;End;

end.

[000419]




Начало  Назад  Вперед



Книжный магазин