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]

Blinkendes TLabel

28. April 2007

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Visible = !Label1->Visible;
}

 [Borland C++ Builder]

#include <jpeg.hpp>

HDC dc = GetDC(NULL);
TJPEGImage *pJPG_Bild = new TJPEGImage();

Graphics::TCanvas *ScreenCanvas = new Graphics::TCanvas();
ScreenCanvas->Handle = dc;

thescreen->AutoSize = true;
thescreen->Center = true;
thescreen->Top = 0;
thescreen->Left = 0;
thescreen->Picture->Bitmap->Width = Screen->Width;
thescreen->Picture->Bitmap->Height= Screen->Height;
TRect rect = Rect(0,0,Screen->Width, Screen->Height);
thescreen->Picture->Bitmap->Canvas->CopyRect(rect, ScreenCanvas, rect);

ReleaseDC(NULL,dc);

pJPG_Bild->Assign(thescreen->Picture->Bitmap);
pJPG_Bild->CompressionQuality = 50;
pJPG_Bild->SaveToFile(“test.jpg”);

delete pJPG_Bild;
delete ScreenCanvas;

 [Borland C++ Builder]

MultiLineCheckBox

28. April 2007

void MultiLineCheckbox(TButtonControl* pmlcheckbox)
{
SetWindowLong(pmlcheckbox->Handle, GWL_STYLE,
GetWindowLong(pmlcheckbox->Handle, GWL_STYLE) | BS_MULTILINE);
}

MultiLineCheckbox(CheckBox1);
CheckBox1->Caption = “Line1 Line2″;

 [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]

Geh ins Menue “Projekt” -> “Optionen”.

Da deaktivierst du unter Registerkarte Linker
“dynamische RTL verwenden”
und unter Registerkarte Packages
“mit Laufzeit-Packages kompilieren”.

Jetzt sollte deine EXE- Datei auch auf Rechnern
laufen die kein BCB installiert haben.

 [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]

Seite 1 von 212