You want to save data to a temporary file but you don’t what to file name to use? Well, this function does all the work for you.
function CreateUniqueFileName(sPath: string): string;
var
chTemp: Char;
begin
repeat
Randomize;
repeat
chTemp := Chr(Random(43) + 47);
if Length(Result) = 8 then
Result := Result + '.'
else if chTemp in ['0'..'9', 'A'..'Z'] then
Result := Result + chTemp;
until Length(Result) = 12;
until not FileExists(sPath + Result);
end;
Categories: General Tags: api, borland, chr, create, Delphi, file, fileexists, filename, generate, Kylix, name, randomize, string string, temporary, temporary file, unique, windows
There are two ways to determine the screen’s height and width.
1) Use the global Screen variable.
uses
Forms;
...
Screen.Height { Screen height in pixels }
Screen.Width { Screen width in pixels }
...
2) Use the Windows API GetSystemMetrics() function. This function can be useful in applications that don’t use the VCL like console applications.
uses
Windows;
...
GetSystemMetric(SM_CXSCREEN) { Screen height in pixels }
GetSystemMetric(SM_CYSCREEN) { Screen width in pixels }
...
Categories: Graphics Tags: api, check, code, Delphi, determine, getsystemmetrics function, height, object pascal, pixels, resolution, screen, size, sm, source, source code, tip, trick, vcl, width, windows, windows api