Q&A

  • DBGrid Memofield로 내용 출력하기..
DBGrid에 Memo필드의 내용 출력하기 예제(아래의 소스)의 DatabaseName은 'DBDEMOS'이고 TableName은 'BIOLIFE.DB' 입니다

여기서DBgrid1drawdatacell 이벤트는 어떤 것이고 Table1Notes: TMemoField에서 TMemoField는 컴포넌트입니까. 아무리 찾아봐도 저한태는 없는것 같고 또한 Memofield로 원하는 데이터를 어떻게 넣는지 궁금합니다.또한 이래의 소스를 실행하면 table1notes:TmemoField가 폼에서 사용되진않은 (혹 선언되지 않은)것이 라고 에러가 뜨는데요?왜인가요?

그리고 프로시저에서 더이상진행이 않되는데 이유가 뭔가여?



//

unit Unit1;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Grids,DBGrids,Db,DBTables, StdCtrls;



type

TForm1 = class(TForm)

Table1: TTable;

DataSource1: TDataSource;

DBGrid1: TDBGrid;

Table1Notes: TMemoField;

Button1: TButton;

procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

Field: TField; State: TGridDrawState);

procedure FormCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

const

MAX_CHARSIZE = 50;

var

Form1: TForm1;



implementation



{$R *.DFM}

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

Field: TField; State: TGridDrawState);

var

P: array [0..MAX_CHARSIZE] of char;

BS: TBlobStream;

S: String;

begin

if Field is TMemoField then

begin

with (Sender as TDBGrid).Canvas do

begin

{Table1Notes 은 TMemoField 형입니다}

BS := tBlobStream.Create(Table1Notes, bmRead);

FillChar(P,SizeOf(P),#0);



BS.Read(P, MAX_CHARSIZE); {blobStream 에서 MAX_CHARSIZE 바이트만큼 읽는다}

BS.Free;

S := StrPas(P);

while Pos(#13, S) > 0 do {CR 문자 제거}

S[Pos(#13, S)] := ' ';

while Pos(#10, S) > 0 do {LF 문자 제거}

S[Pos(#10, S)] := ' ';

FillRect(Rect);

TextOut(Rect.Left, Rect.Top, S);

end;

end;

end;





procedure TForm1.FormCreate(Sender: TObject);

begin



end;



end.



1  COMMENTS
  • Profile
    전철호 1999.06.07 20:11
    한 재 께서 말씀하시기를...

    > DBGrid에 Memo필드의 내용 출력하기 예제(아래의 소스)의 DatabaseName은 'DBDEMOS'이고 TableName은 'BIOLIFE.DB' 입니다

    > 여기서DBgrid1drawdatacell 이벤트는 어떤 것이고 Table1Notes: TMemoField에서 TMemoField는 컴포넌트입니까. 아무리 찾아봐도 저한태는 없는것 같고 또한 Memofield로 원하는 데이터를 어떻게 넣는지 궁금합니다.또한 이래의 소스를 실행하면 table1notes:TmemoField가 폼에서 사용되진않은 (혹 선언되지 않은)것이 라고 에러가 뜨는데요?왜인가요?

    > 그리고 프로시저에서 더이상진행이 않되는데 이유가 뭔가여?

    >

    > //

    > unit Unit1;

    >

    > interface

    >

    > uses

    > Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    > Grids,DBGrids,Db,DBTables, StdCtrls;

    >

    > type

    > TForm1 = class(TForm)

    > Table1: TTable;

    > DataSource1: TDataSource;

    > DBGrid1: TDBGrid;

    > Table1Notes: TMemoField;

    > Button1: TButton;

    > procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

    > Field: TField; State: TGridDrawState);

    > procedure FormCreate(Sender: TObject);

    > private

    > { Private declarations }

    > public

    > { Public declarations }

    > end;

    > const

    > MAX_CHARSIZE = 50;

    > var

    > Form1: TForm1;

    >

    > implementation

    >

    > {$R *.DFM}

    > procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

    > Field: TField; State: TGridDrawState);

    > var

    > P: array [0..MAX_CHARSIZE] of char;

    > BS: TBlobStream;

    > S: String;

    > begin

    > if Field is TMemoField then

    > begin

    > with (Sender as TDBGrid).Canvas do

    > begin

    > {Table1Notes 은 TMemoField 형입니다}

    > BS := tBlobStream.Create(Table1Notes, bmRead);

    > FillChar(P,SizeOf(P),#0);

    >

    > BS.Read(P, MAX_CHARSIZE); {blobStream 에서 MAX_CHARSIZE 바이트만큼 읽는다}

    > BS.Free;

    > S := StrPas(P);

    > while Pos(#13, S) > 0 do {CR 문자 제거}

    > S[Pos(#13, S)] := ' ';

    > while Pos(#10, S) > 0 do {LF 문자 제거}

    > S[Pos(#10, S)] := ' ';

    > FillRect(Rect);

    > TextOut(Rect.Left, Rect.Top, S);

    > end;

    > end;

    > end;

    >

    >

    > procedure TForm1.FormCreate(Sender: TObject);

    > begin

    >

    > end;

    >

    > end.

    >



    제 홈페이지에 가서 보시면 메모,그림을 화면에 디스프레이 하는

    디비그리드 콤포넌트 소스가 있으니 참고하세요.

    홈페이지 주소(http://my.netian.com/~jeon0813)