Ab 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);
}

 [Borland C++ Builder]

for (int i = 0; i < FileListBox1->Items->Count; i++)
{
if (FileListBox1->Selected[i])
{
ShowMessage(FileListBox1->Items->Strings[i]);
}
}

 [Borland C++ Builder]

long 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;
}
}

 [Borland C++ Builder]

RichEdit1->HideSelection = false;
RichEdit1->SelStart=RichEdit1->Lines->Text.Length();

 [Borland C++ Builder]

Canvas mit Farbverlauf

28. April 2007

int 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);
}

 [Borland C++ Builder]

TPoint *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;

 [Borland C++ Builder]

Diesen 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);
}

 [Borland C++ Builder]

odbccp32.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”);
}

 [Borland C++ Builder]

Aus 1000000 wird 1.000.000,00 €.

AnsiString s = FloatToStrF(1000000, ffCurrency, 15, 2);

 [Borland C++ Builder]

char username[256] = {0};
unsigned long laenge = sizeof(username);

GetUserName(username, &laenge);
ShowMessage(AnsiString(username));

 [Borland C++ Builder]

In das Ereignis “OnMouseDown” folgenden Code einfügen und schon kann man das Fenster ohne Titelleiste problemlos verschieben.

if (Button == mbLeft)
{
ReleaseCapture();
SendMessage(this->Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0L);
}

 [Borland C++ Builder]

Bei einer DBLookupComboBox ist es nicht möglich, wie bei einer ComboBox, über die Eigenschaft “Text” einen Wert zu setzen.

Abhilfe schafft die Eigenschaft “KeyValue”.

DBLookupComboBox1->KeyValue = “meinWert”;

 [Borland C++ Builder]

Manchmal ist es auch notwendig bei einem Klick auf “Abbrechen” (Cancel) in einem “OpenDialog” zu reagieren.

Hier ein kleines Code- Beispiel:

if (OpenDialog1->Execute())
{
ShowMessage(“Öffnen gedrückt”);
}else
{
ShowMessage(“Abbrechen gedrückt”);
}

 [Borland C++ Builder]

MessageBox mit TimeOut

28. April 2007

typedef int (WINAPI *MessageBoxTimeOutWFunc)(HWND hWndParent,PWCHAR strText,PWCHAR strCaption, UINT uType,WORD wLanguageId,DWORD dwMilliseconds);

HMODULE hMod = LoadLibrary(“user32.dll”);

MessageBoxTimeOutWFunc pMessageBoxTimeout = (MessageBoxTimeOutWFunc)GetProcAddress(hMod,”MessageBoxTimeoutW”);

pMessageBoxTimeout(NULL,L”Text”,L”Titel”,MB_OK | MB_SETFOREGROUND,0,3000);

FreeLibrary(hMod);

 [WINAPI]

Seite 1 von 11