TMemo – Markierte Zeile ermitteln
28. April 2007 Feedback schreibenAb und an wird auch mal die Zeilennummer der markierten Zeile in einem TMemo gebraucht hier ein Beispiel was ich ganz praktisch finde:
void __fastcall TForm1::Memo1Click(TObject *Sender)
{
int Zeile;
Zeile = SendMessageA(Memo1->Handle, EM_LINEFROMCHAR, Memo1->SelStart, 0);
Edit1->Text = IntToStr(Zeile+1);
}
TFileListBox – Multiselectionen abarbeiten
28. April 2007 Feedback schreibenfor (int i = 0; i < FileListBox1->Items->Count; i++)
{
if (FileListBox1->Selected[i])
{
ShowMessage(FileListBox1->Items->Strings[i]);
}
}
TIdFTP mit TProgressBar verbinden
28. April 2007 Feedback schreibenlong dlsize=IdFTP1->Size(“filename”);
void __fastcall TForm1::IdFTP1WorkBegin(TObject *Sender, TWorkMode AWorkMode, const int AWorkCountMax)
{
if (AWorkCountMax > 0)
{
ProgressBar1->Max=AWorkCountMax;
}else
{
ProgressBar1->Max=dlsize;
}
}
Automatisches scrollen im TRichEdit
28. April 2007 Feedback schreibenRichEdit1->HideSelection = false;
RichEdit1->SelStart=RichEdit1->Lines->Text.Length();
Canvas mit Farbverlauf
28. April 2007 Feedback schreibenint h=Height;
int w=Width;
int mycolor=0;
for(int i=0;i{
mycolor=255*i/h;
Canvas->Pen->Color=TColor(RGB(mycolor,200,200));
Canvas->MoveTo(0,i);
Canvas->LineTo(w,i);
}
Maus – CursorPostion ermitteln
28. April 2007 Feedback schreibenTPoint *mausxy = new TPoint;
GetCursorPos(mausxy);
int x = mausxy->x – Form1->Left;
int y = mausxy->y – Form1->Top;
Label1->Caption = “X= ” + IntToStr(x) + ” Y= ” + IntToStr(y);
delete mausxy;
mehr...DBGrid mit abwechselnder Zeilenfarbe
28. April 2007 Feedback schreibenDiesen Code einfach in das Ereignis “OnDrawColumnCell” vom DBGrid kopieren … fertig.
POINT XYCell={Rect.Left,Rect.Top};
TGridCoord cellColRow;
::ClientToScreen(DBGrid1->Canvas->Handle,(LPPOINT)&XYCell);
cellColRow=DBGrid1->MouseCoord(XYCell.x,XYCell.y);
if(cellColRow.Y % 2)
{
DBGrid1->Canvas->Brush->Color = 0×00F1F1F1;
}else
{
DBGrid1->Canvas->Brush->Color = 0×00FFFFFF;
DBGrid1->Canvas->FillRect(Rect);
}
DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);
if (State.Contains(gdSelected))
{
DBGrid1->Canvas->Brush->Color = clSkyBlue;
DBGrid1->Canvas->FillRect(Rect);
DBGrid1->Canvas->DrawFocusRect(Rect);
DBGrid1->DefaultDrawColumnCell(Rect, DataCol, Column, State);
}
ODBC-Datenquelle zur Laufzeit hinzufügen
28. April 2007 Feedback schreibenodbccp32.lib -> zum Projekt hinzufügen
#include <odbcinst.h>
char buffer[MAXPATH];
extern String Arbeitsverzeichnis = getcwd(buffer, MAXPATH);
AnsiString dbqStr = Arbeitsverzeichnis + “Datenbankdatei.mdb”;
AnsiString strAttribs = “DSN=Datenbankname”;
strAttribs += ‘’;
strAttribs += “DBQ=” + dbqStr;
strAttribs += ‘’;
if(SQLConfigDataSource ( NULL, ODBC_ADD_DSN, “Microsoft Access Driver (*.mdb)”, strAttribs.c_str() ))
{
ADOConnection1->Connected = true;
}else
{
ShowMessage(“Fehler beim anlegen der ODBC-Datenquelle”);
}
Windows Benutzername abfragen
28. April 2007 Feedback schreibenchar username[256] = {0};
unsigned long laenge = sizeof(username);
GetUserName(username, &laenge);
ShowMessage(AnsiString(username));



