f-print

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
quasi
Üye
Mesajlar: 34
Kayıt: 07 Tem 2003 06:32
Konum: Denizli
İletişim:

f-print

Mesaj gönderen quasi »

Problemim Şu CBuilder ile yazılmış olan Fprint.cpp dosyasını
Delphi 3.0 da kullanmak ,istiyorum. Fprint .cpp dosyası Form üzerindeki
DBGrid direk yazdırabilme imkanı sağlıyor.
Nasıl kullanabilirim?

İkinci olarak, Form üzerindeki sadece DBGrid`i nasıl yazdırabilirim.

Yazdırma işlerinde kullanabileceğim iyi bir fonksiyon, komponent önerebilirmisiniz?

Son Sorum: Bir bilgisayarda Delphi ile yazılan bir programın
başka bilgisayarlarda çalışması için minimum gerekli Sistem vb..
dosyalar nelerdir?


FPRINT kodları:
...........................
#include "FPRINT.H"

//---------------------------------------------------------------------------
TFPrint::TFPrint()
{
mLeft = 10;
mRight = 20;
mTop = 20;
mBottom = 20;
rowSpace = 2;
pFont = new TFont;
MaxGrWidth = NULL;

pFont->Color = clBlack;
pFont->Size = 10;
TextAlign = taRightJustify;
DrawLines = false;
PageScale = 1;
VisibleRowNumber = true;
}
//---------------------------------------------------------------------------

void TFPrint::PrnText( int x, int y, AnsiString PStr )
{
Printer()->Canvas->Font = pFont;
Printer()->Canvas->TextOut( x, y, PStr );
}
//---------------------------------------------------------------------------
void TFPrint::PrintTextMM( int x, int y, AnsiString PStr )
{
int pX, pY; // Pixels
pX = ( 10*x*GetPixelsPerInch( pHORIZONTAL ) )/254 ;
pY = ( 10*y*GetPixelsPerInch( pVERTICAL ) )/254 ;

Printer()->Canvas->Font = pFont;
Printer()->Canvas->TextOut( pX, pY, PStr );
}

//---------------------------------------------------------------------------
int TFPrint::GetPixelsPerInch( TPixellPerInch Value )
{
if ( Value == pHORIZONTAL )
return GetDeviceCaps( Printer()->Handle, LOGPIXELSX );
else
return GetDeviceCaps( Printer()->Handle, LOGPIXELSY );
}
//---------------------------------------------------------------------------
int TFPrint::AlignText( AnsiString PStr, enum TAlignment fAlign )
{
int PosX;
Printer()->Canvas->Font = pFont;

switch( fAlign )
{
case taLeftJustify:
PosX = mLeft;
break;
case taCenter:
PosX = Printer()->PageWidth/2 - Printer()->Canvas->TextWidth(PStr)/2;
break;
case taRightJustify:
PosX = Printer()->PageWidth - Printer()->Canvas->TextWidth(PStr)- mRight;
break;
}
return PosX;
}

//---------------------------------------------------------------------------
void TFPrint::RecText( int x, int y, AnsiString Text )
{
TRect ARect;
int yPos, xPos;

Printer()->Canvas->Font = pFont;
rowHeight = Printer()->Canvas->TextHeight("ABCDabcd") + rowSpace;
yPos = y*rowHeight;

if( TextAlign == taRightJustify )
xPos = x + rowWidth - Printer()->Canvas->TextWidth(Text);
else if( TextAlign == taCenter )
xPos = x + (rowWidth - Printer()->Canvas->TextWidth(Text))/2;
else
xPos = x+2;

Printer()->Canvas->Pen->Color = pFont->Color;
Printer()->Canvas->Brush->Style = bsClear;
Printer()->Canvas->Pen->Style = psSolid;
Printer()->Canvas->Pen->Width = 1;

ARect.Left = x;
ARect.Top = yPos;
ARect.Bottom = yPos + rowHeight;
ARect.Right = x + rowWidth;

if( DrawLines )
Printer()->Canvas->Rectangle(ARect);

Printer()->Canvas->TextRect(ARect, xPos, yPos + rowSpace/2, Text);
}

//---------------------------------------------------------------------------
int TFPrint::RowHeight( void )
{
return Printer()->Canvas->TextHeight("ABCDabcd") + rowSpace;
}
//---------------------------------------------------------------------------

void TFPrint::PrnGrid( TDBGrid *Grd, int Line )
{
AnsiString strDisplayName;

TDataSet *Tbl = Grd->DataSource->DataSet;
int MAX_GRID_COUNT = Grd->Columns->Count;
int * HorizPgIndex = new int[MAX_GRID_COUNT];
MaxGrWidth = new int[MAX_GRID_COUNT];
float * Scala = new float[MAX_GRID_COUNT/2];
int tLine = 0;
int rowNumWidth;

int hPgCount; // Dikey olarak sayfa sayısı
int infRow;

float topGrdLenght = 0;
int pgEndLine, PageNo;

Printer()->Canvas->Font = pFont;

rowNumWidth = Printer()->Canvas->TextWidth("999 - ");
pgWidth = Printer()->PageWidth - mLeft - mRight - rowNumWidth;
pgHeight = Printer()->PageHeight;
rowHeight = Printer()->Canvas->TextHeight("ABCDabcd") + rowSpace;

pgEndLine = (pgHeight / rowHeight) - 2;
PageNo = 1;
hPgCount = 0;

for (int i = 0; i < MAX_GRID_COUNT; i ++)
{
strDisplayName = Grd->Columns->Items->Title->Caption.c_str();
rowWidth = Printer()->Canvas->TextWidth(strDisplayName);

Tbl->First();
do
{
int gWidth;
gWidth = Printer()->Canvas->TextWidth(
Grd->Columns->Items->Field->DisplayText);
if(rowWidth < gWidth)
rowWidth = gWidth;

Tbl->Next();
}while(!Tbl->Eof);

MaxGrWidth = rowWidth;
if((topGrdLenght + rowWidth) >= pgWidth)
{
Scala[hPgCount] = (pgWidth+mRight)/topGrdLenght;
HorizPgIndex[hPgCount] = i;
topGrdLenght = 0;
hPgCount ++;
}
else
topGrdLenght = topGrdLenght + MaxGrWidth;
}

Scala[hPgCount] = pgWidth/topGrdLenght;
HorizPgIndex[hPgCount] = MAX_GRID_COUNT;

//Sadece bir sayfalık(yatay konum)
PageScale = Scala[0];

int Basl, Sayac;
int xPos, cLine;

xPos = mLeft + rowNumWidth;
cLine = Line;
tLine = 1;
Sayac = hPgCount;
Basl = 0;
hPgCount = 0;
infRow = 0;

do
{
// DBGrid in Başlıklarının yazılması
for (int j = Basl; j < HorizPgIndex[hPgCount]; j ++)
{
rowWidth = (int)MaxGrWidth[j]*Scala[hPgCount];
strDisplayName = Grd->Columns->Items[j]->Title->Caption;

// DBGrid in text yerleşim ayarlarını al
TextAlign = Grd->Columns->Items[j]->Title->Alignment;
RecText( xPos, cLine, strDisplayName );
xPos = xPos + rowWidth;
}

if ( cLine == Line )
{
Printer()->Canvas->Pen->Color = pFont->Color;
Printer()->Canvas->Brush->Style = bsClear;
Printer()->Canvas->Pen->Style = psSolid;
Printer()->Canvas->Pen->Width = 1;
Printer()->Canvas->MoveTo( mLeft, (cLine+1)*rowHeight+5 );
Printer()->Canvas->LineTo( pgWidth + mRight + rowNumWidth, (cLine+1)*rowHeight+5 );
}

xPos = mLeft + rowNumWidth;
cLine = cLine + 2;

Tbl->First();
do
{
if( cLine == pgEndLine )
{
PrnText( AlignText("99", taCenter), pgEndLine, IntToStr(PageNo) );
Printer()->NewPage();
PageNo = PageNo + 1;
// tLine ++;
cLine = 1;//Line;
}
for (int j = Basl; j < HorizPgIndex[hPgCount]; j ++)
{
rowWidth = (int)MaxGrWidth[j]*Scala[hPgCount];
strDisplayName = Grd->Columns->Items[j]->Field->DisplayText;
if( j == 0 && strDisplayName.Trim() == "" )
infRow = 1;

// DBGrid in text yerleşim ayarlarını al
TextAlign = Grd->Columns->Items[j]->Alignment;
RecText( xPos, cLine, strDisplayName );
xPos = xPos + rowWidth;
}

if( !infRow && VisibleRowNumber )
{
TextAlign = taLeftJustify;
RecText( mLeft, cLine, IntToStr(tLine++) );
}
infRow = 0;

EndLine = (cLine+1)*rowHeight;
xPos = mLeft + rowNumWidth;
cLine = cLine + 1;
Tbl->Next();
}while(!Tbl->Eof);
Tbl->First();

hPgCount ++;
if(hPgCount != Sayac+1)
{
Printer()->NewPage();
Basl = HorizPgIndex[hPgCount-1];
cLine = 1;//Line;
tLine ++;
xPos = mLeft + rowNumWidth;
}
}while(hPgCount != Sayac+1);

delete HorizPgIndex;
delete Scala;
}

//------------------------------------------------------------------------------
bool TFPrint::SetCustomPrintSize( int CustomWidth, int CustomLength )
{
TSetPrinterPageSize *NewCustomPrintSize = new TSetPrinterPageSize();

NewCustomPrintSize->SetPage( Printer(), CustomWidth, CustomLength );

delete NewCustomPrintSize;
return true;
}

//------------------------------------------------------------------------------
void TFPrint::Start(void)
{
Printer()->BeginDoc();
}

void TFPrint::Stop(void)
{
Printer()->EndDoc();
}

TFPrint::~TFPrint()
{
delete pFont;
if ( MaxGrWidth != NULL )
delete MaxGrWidth;
}
..........................................................................................
Cevapla