Archiv für Delphi
Random String
Samstag, 12. Mai 2007LoopInt : Integer;
DirName, FullName, RanStr : String;
FileSavedTo : TextFile;
// Length of string to create
RandArray : Array[0..4087] Of Char;
FirstCount : Extended;
begin
FirstCount := GetTickCount;
Label2.Caption := ”;
Randomize;
RanStr := ”;
DirName := Directory95ListBox1.Directory;
If DirName[Length(DirName)] <> ‘\’ Then DirName := DirName + ‘\’;
FullName := DirName + Edit1.Text;
If FileExists(FullName) Then DeleteFile(FullName);
For LoopInt := Low(RandArray) To High(RandArray) Do
Begin
RanStr := RanStr + Chr(Random(255 - 32 + 1) + 32);
End;
AssignFile(FileSavedTo, FullName);
If FileExists(FullName) Then
Reset(FileSavedTo)
Else
Rewrite(FileSavedTo);
Writeln(FileSavedTo, RanStr);
CloseFile(FileSavedTo);
Label2.Caption := ‘DONE’;
Label4.Caption := FloatToStr((GetTickCount - FirstCount) / 1000);
FileListBox1.Update;
[tags]Delphi, Strings[/tags]
Strip Comments from String
Samstag, 12. Mai 2007STRIP_STATES = ( SS_NORMA, SS_BRACE, SS_PAREN, SS_LITER );
function SCFS( const S : string; var SS : STRIP_STATES ): string;
// strip comments from string
var
I : integer;
begin
Result := ”;
I := 1;
while I <= Length( S ) do begin
case SS of
SS_NORMA :
case S[ I ] of
‘{‘ : if ( I < Length( S ) ) and ( S[ I + 1 ] = ‘$’ )
then Result := Result + S[ I ]
else SS := SS_BRACE;
‘(‘ : if ( I < Length( S ) ) and ( S[ I + 1 ] = ‘*’ )
then begin
if ( I < Length( S ) - 1 ) and ( S[ I + 2 ] = ‘$’ )
then Result := Result + S[ I ]
else begin SS := SS_PAREN; Inc( I ); end;
end else Result := Result + S[ I ];
‘/’ : if ( I < Length( S ) ) and ( S[ I + 1 ] = ‘/’ )
then Exit
else Result := Result + S[ I ];
”” : begin SS := SS_LITER; Result := Result + S[ I ]; end;
else Result := Result + S[ I ];
end;
SS_BRACE :
case S[ I ] of
‘}’ : SS := SS_NORMA;
end;
SS_PAREN :
case S[ I ] of
‘*’ : if ( I < Length( S ) ) and ( S[ I + 1 ] = ‘)’ )
then begin SS := SS_NORMA; Inc( I ); end;
end;
SS_LITER :
case S[ I ] of
”” : begin SS := SS_NORMA; Result := Result + S[ I ]; end;
else Result := Result + S[ I ];
end;
end; // case
SS of
Inc( I );
end; // while I <= Length( S ) do begin
end; // SCFS
procedure STRIP_COMMENTS( slIN, slOUT : TStringList;
EMPTY_LINES : boolean = false; // True – to preserve empty lines
LEFT_TRIM : boolean = false; // True – to strip indentation
RIGHT_TRIM : boolean = true ); // False – to preserve right white spaces
// strips Object Pascal’s comments
// slIN – input, slOUT – output
var
I : integer;
STRIP_STATE : STRIP_STATES;
S : string;
begin
STRIP_STATE := SS_NORMA;
for I := 0 to slIN.Count - 1 do begin
S := SCFS( slIN[ I ], STRIP_STATE );
if LEFT_TRIM then S := TrimLeft( S );
if RIGHT_TRIM then S := TrimRight( S );
if EMPTY_LINES or ( Length( Trim( S )) > 0 ) then slOUT.Append( S );
end;
end; // STRIP_COMMENTS
[tags]Delphi, Strings[/tags]
Tokenizing
Samstag, 12. Mai 2007Tokenize a string:
ExtractString (Classes.pas)
[tags]Delphi, Strings[/tags]
How to play system-Sounds?
Samstag, 12. Mai 2007Q:How to play system-Sounds?
A:
PlaySound(‘SystemExclamation’,0,SND_ALIAS or SND_ASYNC);
PlaySound(‘SystemAsterisk’,0,SND_ALIAS or SND_ASYNC);
You can look in the registry to find all available sound alias‘
HKEY_CURRENT_USER\AppEvents\EventLabels
And here for the actual sound reference:
HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default
[tags]Delphi, Sound[/tags]
Installer: GPInstall
Samstag, 12. Mai 2007Installer written in delphi:
http://www.qsc.co.uk/gpinstall/gpinstall.htm
[tags]Delphi, Shareware, Installer[/tags]
Installer: InnoSetup
Samstag, 12. Mai 2007> Hi Art what is the URL of Inno-setup
http://www.innosetup.com
[tags]Delphi, Shareware, Installer[/tags]
Nasty nag crap
Samstag, 12. Mai 2007In your FormShow event:
var atom : integer;
CRLF : string;
begin
if
GlobalFindAtom(‘THIS_IS_SOME_OBSCUREE_TEXT’) = 0 then
atom := GlobalAddAtom(‘THIS_IS_SOME_OBSCUREE_TEXT’)
else
begin
CRLF := #10 + #13;
ShowMessage(‘This version may only be run once for every Windows Session.’ + CRLF +
‘To run this program again, you need to restart Windows, or better yet:’ + CRLF +
‘REGISTER !!’);
Close;
end;
end;
{ The advantages here are that you leave all the functionallity at the users disposal, but
the moment he closes the program, its bootie-time, folks ! All you got to do is write
some obscure text and save it in the Windows global atom table. }
[tags]Delphi, Shareware[/tags]
A Better Way To Print a Form
Samstag, 12. Mai 2007Technical Information Database
TI1412D.txt A Better Way To Print a Form
Category :General Programming
Platform :All
Product
elphi All
Description:
The following TI details a better way to print the contents of
a form, by getting the device independent bits in 256 colors
from the form, and using those bits to print the form to the
printer.
weiterlesen »
Print Bitmap as DIB
Samstag, 12. Mai 2007Print Bitmap as DIB
by Boris Nienke
(you need a Form with a TImage and a TButton)
- just for 24bit bitmaps. If bitmaps has less bits, then there may be a blank page on some HP printers! You can change color-depth with: “MyBitmap.PixelFormat := pf24bit”.
- or you need to fill the palette-entries (look at “A Better Way to Print a Form” (Borland Technical Info TI1412D.txt)
weiterlesen »
QuickReport and Win2000
Samstag, 12. Mai 2007> a client using a Delphi program written by me installed Win2k on his
> Computer and now some QuickReports don’t work. With Windows 95 and WinNT
> all works fine. I heard now, that there is a problem with Win2k and QR.
>
> can anybody help me . . .
1) open the qprev.dfm (With Delphi)
2) find the properties ‘enabled = false’ of
Printer setup & printer icons and set
them to ‘enabled = true’
3) save the DFM and recompile…
voila now works under win2k =)
—————–
thank you for answering. Sorry that I couldn’t find the qprev.dfm. There
exists a qrprev.dfm but without the properties you wrote about. I work with
Delphi 4 and QReport 3.0.3.
——————
Try to fint these values in DFM:
…
Enabled = False
…
object Print: TToolButton
…
Enabled = False
…
Now change the False into True and save
the DFM …
[tags]Delphi, Printing[/tags]