Autor Beitrag
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 10.12.04 10:13 
Hab ein Problem mit einem DBGrid , da ja leider Felder von Typ Tmemofield nicht angezeigt werden hab ich folgendes Script erstellt

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
procedure Tfrm_mdi_rechnung_suchen.dbg_tempDrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
var i, weite:integer;
    s,t:string;
begin
  inherited;
  if field is Tmemofield then
  begin
    with  dbg_temp.Canvas do
    begin
      weite:=Rect.Right-Rect.Left - Textwidth('...');
      s:=field.asstring;
      i:=0;
      repeat
        inc(i);
        t:=copy(s,1,i);
      until ((textwidth(t) > weite) OR (i > length(s)));
      t:= copy(s,1,i-1);
      fillrect(rect);
      if trim(t) <> trim(s) then
        textrect(rect,rect.Left+1,rect.top+2,t+'...')
      else
        textrect(rect,rect.Left+1,rect.top+2,t);
    end; //gabfrage.Canvas
  end
  else
  begin
    dbg_temp.DefaultDrawDataCell(Rect, Field, State);
  end;
end;


dass funktioniert auch sehr gut, es hat nur einen Haken, denn man muss ja defaultdrawing abschalten. dadurch geht das alignment der TColumn verloren. Der Versuch die Spalten vorzudefinieren scheitert daran dass dann der onDrawDataCell Event nicht ausgelöst wird. und die Zelle danach zu formatieren bringt nichts weil das DefaultDrwaing ja aus ist.

Ich muss wohl im Event das Alignment der Column händisch bearbeiten, aber wie und wo ?

_________________
mfg. Joel
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Fr 10.12.04 10:20 
Hallo!

Probiere es mal mit dem Ereignis TField.OnGetText.

Cu,
Udontknow
JoelH Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 10.12.04 10:54 
Titel: hmm,
wie meinst dass jetzt genau *aufschlauchsteh* ?

_________________
mfg. Joel
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Fr 10.12.04 13:38 
Nun, jeder TField-Nachfahre, also auch dein TMemoField-Objekt, hat ein Ereignis OnGetText, das eine Manipulation des Textes ermöglicht, der beispielsweise in DBEdits oder auch in DBGrids ausgegeben wird.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TDM.MyCDSMyMemoFieldGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
  Text:='Dies ist ein Test';
end;

...
  MyDataset.Open;  
  MyDataset.FieldByName('MyMemo').OnGetText:=MyCDSMyMemoFieldGetText;
  MyDatasource.Dataset:=MyDataset;

...


Cu,
Udontknow
JoelH Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 10.12.04 14:13 
Titel: hmm,
das ist zu einfach gewesen ;) Funktioniert supi, danke.

_________________
mfg. Joel