Autor Beitrag
OliverN_26
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Do 31.01.08 01:07 
Hi.

Also ... ich lade aus ner txt jede Menge Werte. Mittendrin hab ich dann nen Wert, der ne Beschreibung enthält. Ich möchte jetzt den Wert in die Zelle schreiben und die Beschreibung als Hint. Geht das irgendwie?
Bis jetzt hab ich irgendwie immer nur Sachen gefunden, wo man über die MouseMove Methode den Inhalt der Zelle anzeigen kann.
bin am überlegen ob ich die Beschreibungen nich erst mal mit ner Routin in nen Array lade, wobei dann immer noch die Frage besteht, wie ich die Array Inhalte einer einzelnen StringGrid Zelle zuweisen kann.

Bitte um Hilfe :-(

Danke
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Do 31.01.08 03:28 
Soweit ich weis kann man nicht jeder Zelle eines StringGrids einen Hint zuweisen.
Aber mit dem VirtualTreeView geht das
www.soft-gems.net/in...;id=12&Itemid=38
www.delphi-treff.de/...n32/virtualtreeview/
Ja, das kannst du so zurechtfriemeln, dass es wie eine Tabelle aussieht.
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: Do 31.01.08 04:37 
Ich fummle mit diesem Source an den namen des popupmenüs rumm. (jede Zeile anderes Popup)
wenn man das ganze in das MouseMove des Grids verschiebt und dabei an dem Hint rummschraubt sollte es funken.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.SGWarenMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Z,S : integer;
begin
  SGWaren.MouseToCell(X,Y,S,Z);
  if Z = 0 then Exit;
  LastWare := Z - 1;
  SGWaren.Row := Z;
  PopupMenu1.Items.Items[0].Caption := WarenDA[LastWare].Name + ' anpflanzen';
  PopupMenu1.Items.Items[1].Caption := WarenDA[LastWare].Name + ' anpflanzen und giessen';
  PopupMenu1.Popup(mouse.CursorPos.X,mouse.CursorPos.y);
end;

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
hazard999
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 162

Win XP SP2
VS 2010 Ultimate, CC.Net, Unity, Pex, Moles, DevExpress eXpress App
BeitragVerfasst: Do 31.01.08 07:52 
Hallo,

Versuch mal:

ausblenden volle Höhe 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:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
procedure TForm.StringGridMouseMove(Sender: TObject;
   Shift: TShiftState; X, Y: Integer);
var ACol, ARow: integer;
begin
   StringGrid.MouseToCell(X, Y, ACol, ARow);

   if ACol > -1 then
   begin
      if (ACol <> MouseCol) or (aRow <> MouseRow) then
      begin
         postmessage(TMyStringGrid(sender).handle, cm_mouseleave, 0, 0);
         MouseCol := ACol;
         MouseRow := ARow;
         postmessage(TMyStringGrid(sender).handle, cm_mouseenter, 0, 0);
      end;
   end
   else
   begin
      MouseCol := -1;
      if assigned(hint) then
         hint.ReleaseHandle;
   end;
end;

procedure TMyStringGrid.CMMouseLeave(var Message: TMessage); message CM_MouseLeave;
begin
   if assigned(hint) then
      hint.ReleaseHandle;
end;


procedure TMyStringGrid.CMMouseEnter(var message: TMessage);message CM_MouseEnter;
var
   hilf: TRect;
   texti: string;

   function GetCursorHoehe: Integer;
   var
      IconInfo: TIconInfo;
      BitmapInfoSize, BitmapBitsSize, ImageSize: DWORD;
      Bitmap: PBitmapInfoHeader;
      Bits: Pointer;
      BytesPerScanline: Integer;

      function FindScanline(Source: Pointer; MaxLen: Cardinal;
         Value: Cardinal): Cardinal; assembler;
      asm
         PUSH    ECX
         MOV     ECX,EDX
         MOV     EDX,EDI
         MOV     EDI,EAX
         POP     EAX
         REPE    SCASB
         MOV     EAX,ECX
         MOV     EDI,EDX
      end; // function FindScanline(Source: Pointer; MaxLen: Cardinal;

   begin
      Result := GetSystemMetrics(SM_CYCURSOR);
      if GetIconInfo(GetCursor, IconInfo) then
         try // finally
            GetDIBSizes(IconInfo.hbmMask, BitmapInfoSize, BitmapBitsSize);
            Bitmap := AllocMem(DWORD(BitmapInfoSize) + BitmapBitsSize);
            try
               Bits := Pointer(DWORD(Bitmap) + BitmapInfoSize);
               if GetDIB(IconInfo.hbmMask, 0, Bitmap^, Bits^) and (Bitmap^.biBitCount = 1) then
               begin
                  with Bitmap^ do
                  begin
                     BytesPerScanline := ((biWidth * biBitCount + 31) and not 31) div 8;
                     ImageSize := biWidth * BytesPerScanline;
                     Bits := Pointer(DWORD(Bits) + BitmapBitsSize - ImageSize);
                     Result := FindScanline(Bits, ImageSize, $FF);
                     if (Result = 0) and (biHeight >= 2 * biWidth) then
                        Result := FindScanline(Pointer(DWORD(Bits) - ImageSize),
                           ImageSize, $00);
                     Result := Result div BytesPerScanline;
                  end; // with Bitmap^ do
                  Dec(Result, IconInfo.yHotSpot);
               end; // if GetDIB(IconInfo.hbmMask, 0, Bitmap^, Bits^) and (Bitmap^.biBitCount = 1) then
            finally
               FreeMem(Bitmap, BitmapInfoSize + BitmapBitsSize);
            end; // try
         finally
            if IconInfo.hbmColor <> 0 then
               DeleteObject(IconInfo.hbmColor);
            if IconInfo.hbmMask <> 0 then
               DeleteObject(IconInfo.hbmMask);
         end; // try
   end; // function GetCursorHoehe: Integer;

begin
      if (MouseCol >= 0) and (MouseRow >= 0) then
      begin
         Texti := Cells[MouseCol, MouseRow];
         if (Texti <> '') and assigned(hint) and (MouseRow > 1) and (MouseCol >= 0) and (MouseCol <= 1) then
         begin
            Timer1.enabled := false;
            hilf.left := mouse.cursorpos.x;
            hilf.right := hilf.left + Hinti.Canvas.TextWidth(texti) + 10;
            hilf.top := mouse.cursorpos.y + GetCursorHoehe;
            hilf.bottom := hilf.top + hint.Canvas.TextHeight(texti) + 2;
            hint.ReleaseHandle;
            hint.brush.color := GetSysColor(COLOR_INFOBK);
            hint.ActivateHint(hilf, texti);
            Timer1.enabled := true;
         end;
      end;
end;


CM_MouseEnter und CM_MouseLeave sind einfach WM_USER + irgendwas...

r u

René

_________________
MOV EAX, Result;MOV BYTE PTR [EAX], $B9;MOV ECX, M.Data;MOV DWORD PTR [EAX+$1], ECX;MOV BYTE PTR [EAX+$5], $5A;MOV BYTE PTR [EAX+$6], $51;MOV BYTE PTR [EAX+$7], $52;MOV BYTE PTR [EAX+$8], $B9;MOV ECX, M.Code;MOV DWORD PTR [EAX+$9], ECX
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 31.01.08 09:22 
Hallo,

bei den Schweitzern findet an immer ganz nette Sachen:
...im StringGrid den Zelleninhalt als Hint anzeigen?

user profile iconOliverN_26 hat folgendes geschrieben:
...bin am überlegen ob ich die Beschreibungen nich erst mal mit ner Routin in nen Array lade, wobei dann immer noch die Frage besteht, wie ich die Array Inhalte einer einzelnen StringGrid Zelle zuweisen kann.
Das ist der richtige Ansatz.

Bau Dir ein Array entsprechend der Größe des des Arrays StringGrid.Cells[...,...].
Dann musst Du nur noch die eine Code-Zeile von den Schweitzern anpassen:
ausblenden Delphi-Quelltext
1:
2:
//StringGrid.Hint:=StringGrid.Cells[ACol,ARow];
StringGrid.Hint := MyArrBeschreibungen[ACol,ARow];

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Do 31.01.08 10:49 
Danke für eure Tips ...

Mit dem Array hab ich ein Problem, da ich ne Menge Werte aus ne txt einlese. Wenn ich nun zu jedem Wert die Beschreibung einfach in nen Array lade, ist die Referenz bissl schwierig nachzuvollziehen.

Ich habs jetz folgender Maßen gelöst:
Ich habe ein 2. StringGrid, als ne Art TempTable angelegt und visible:= false gesetzt. Wenn ich nun aus der txt lade, lade ich den Wert in das sichtbare und die Beschreibung 1:1 in das 2 nicht sichtbare. Mit MouseMove referenzier ich dann von der Zelle aus dem 1.StringGrid auf das 2.!

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var ACol, ARow: longint;
begin
  StringGrid1.MouseToCell(X, Y, ACol, ARow);
  StringGrid1.Hint:=StringGrid2.Cells[ACol,ARow];
  if (ACol<>LastCol) or (ARow<>LastRow) then begin
    Application.CancelHint;
    LastCol:=ACol;
    LastRow:=ARow;
  end;
end;


Funzt super :-)

Danke euch allen.


Zuletzt bearbeitet von OliverN_26 am Do 31.01.08 10:54, insgesamt 1-mal bearbeitet
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Do 31.01.08 10:49 
Ol
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 31.01.08 12:03 
Wobei ich mich frage, wo da der Unterschied zu einem alleinigen Array ist, schließlich ist Cells ja im Grunde auch nix anderes. Es ist kein guter Programmierstil, visuelle Komponenten zu missbrauchen, nur weil man ein paar Zeilen Code sparen will... (Das ist ja im Grunde fast das selbe, SetLength statt Zeilen- und Spaltenanzahl setzen, und eben in das Array schreiben bzw. daraus lesen statt Cells zu benutzen.)