Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread subclassedTEDBTable - added truncation
Tue, Sep 2 2008 8:26 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

As I just reminded someone truncation is also needed.

unit nlhTable;

interface

uses
SysUtils, Classes, DB, edbcomps;

type
TnlhTable = class(TEDBTable)
private
   { Private declarations }
 FRTrimStrings: boolean;
 FTruncate: boolean;
 FNullEmptyStrings: boolean;
protected
   { Protected declarations }
 procedure InternalPost; override;
public
   { Public declarations }
 constructor Create(AOwner: TComponent); override;
published
   { Published declarations }
 property RTrimStrings: boolean read FRTrimStrings write FRTrimStrings;
 property Truncate: boolean read FTruncate write FTruncate;
 property NullEmptyStrings: boolean read FNullEmptyStrings write FNullEmptyStrings;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('ElevateDB', [TnlhTable]);
end;

{ TnlhTable }

constructor TnlhTable.Create(AOwner: TComponent);
begin
inherited;
FRTrimStrings := True;
FNullEmptyStrings := True;
end;

procedure TnlhTable.InternalPost;
var
Cntr: integer;
Interim: string;
begin
if FTruncate or FRTrimStrings or FNullEmptyStrings then begin
 for Cntr := 0 to Fields.Count - 1 do begin
  if Fields[Cntr].DataType in [ftString, ftMemo, ftFmtMemo] then begin
   if not Fields[Cntr].IsNull then begin
    if FRTrimStrings then Interim := TrimRight(Fields[Cntr].AsString);
    if FNullEmptyStrings then if Interim = '' then Fields[Cntr].Clear else Fields[Cntr].AsString := Interim;
    if FTruncate and (Fields[Cntr].DataType = ftString) and (Length(Interim) > Fields[Cntr].Size) then Interim := Copy(Interim, 1, Fields[Cntr].Size);
   end;
  end else if Fields[Cntr].DataType in [ftBlob, ftGraphic] then begin
   if (not Fields[Cntr].IsNull) and FNullEmptyStrings and (Fields[Cntr].AsString = '') then Fields[Cntr].Clear;
  end;
 end;
end;
inherited;
end;

end.


Roy Lambert
Tue, Sep 2 2008 8:40 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Just ignore this one - I keep forgetting that TDataSet does the truncation

Roy Lambert
Image