الاخوة الكرام استخدم قاعدة اكسس ويوجد بها حقل من نوع Memo فكيف يمكن اظهار محتوياته على الــDBGrid مع العلم انه يظهر فقط كلمة Memo .
تحياتي
الاخوة الكرام استخدم قاعدة اكسس ويوجد بها حقل من نوع Memo فكيف يمكن اظهار محتوياته على الــDBGrid مع العلم انه يظهر فقط كلمة Memo .
تحياتي
السلام عليكم هذا الرد منقول من احدى المواقع الممتازه ولم اجربه
Q. How do I show the contents of a memo field in a DBGrid?
A. Use the following code for the OnDrawDataCell event of the DBGrid. Note: before running create a TMemoField object for the memo field by double clicking on the TTable component and adding the memo field.
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
var
P : array [0..50] of char; {array size is number of characters needed}
BS : tBlobStream; {from the memo field}
S : String;
begin
If Field is TMemoField then begin
with (Sender as TDBGrid).Canvas do begin
{Table1Notes is the TMemoField}
BS := tBlobStream.Create(Table1Notes, bmRead);
FillChar(P,SizeOf(P),#0); {terminate the null string}
BS.Read(P, 50); {read 50 chars from memo into blobStream}
BS.Free;
S := StrPas(P);
while Pos(#13, S) > 0 do {remove carriage returns and}
S[Pos(#13, S)] := ' '; {line feeds}
While Pos(#10, S) > 0 do
S[Pos(#10, S)] := ' ';
FillRect(Rect); {clear the cell}
TextOut(Rect.Left, Rect.Top, S); {fill cell with memo data}
end;
end;
end;
ملحوظة:-
العنوان هو
شكرا لك اخي الكريم هانى ابو مهند
لكن الكود لم يعمل معي فهل بلامكان المساعدة
تحياتي
خي الكريم اتبع الخطوات وإن شاء الله سوف يعمل
إضغط بالزر اليميني للماوس على العنصر table
وقم باختيار add fildes وهو الحقل الذي من النوع
memo
واسمه افتراضيا في الكود note
ومن ثم داخل الحدث OnDrawDataCell
ضع الكود الذي أشار إليه الأخ هاني
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
var
P : array [0..50] of char; {array size is number of characters needed}
BS : tBlobStream; {from the memo field}
S : String;
begin
If Field is TMemoField then begin
with (Sender as TDBGrid).Canvas do begin
{Table1Notes is the TMemoField}
BS := tBlobStream.Create(Table1Notes, bmRead);
FillChar(P,SizeOf(P),#0); {terminate the null string}
BS.Read(P, 50); {read 50 chars from memo into blobStream}
BS.Free;
S := StrPas(P);
while Pos(#13, S) > 0 do {remove carriage returns and}
S[Pos(#13, S)] := ' '; {line feeds}
While Pos(#10, S) > 0 do
S[Pos(#10, S)] := ' ';
FillRect(Rect); {clear the cell}
TextOut(Rect.Left, Rect.Top, S); {fill cell with memo data}
end;
end;
endحيث أن الكود السابق يعمل في حال أنك تدخل البيانات للحقل عن طريق أي عنصر مربوط مع الحقل
وسأحاول إن شاء الله بإيجاد طريقة للوصول إلى الكتابة في dbgrid مباشرة
إلى الحقل memo
مندون استعمال
شكرا اخ reda
على ردك وتجاوبك معنا
وعند تنفيذ توجيهاتك وعندما اعمل تنفيذ البرنامج يعطيني خطـأ على هذا الامر
BS : tBlobStream; {from the memo field}
فما المقصود
واعذر اخوك ترى شويه معلماني :D
تحياتي
أخ ابو أحمد أسف لقد جربت الكود على قاعدة بيانات من نوع paradox
وإن شاء الله سأجربه على قاعدة بيانات access
هذا الموضوع مغلق.