function fibit(n: Integer): Integer;
var
a, b, i, temp: Integer;
begin
temp := 1;
a := 1;
b := 1;
for i := 1 to n - 1 do
begin
temp := a + b;
a := b;
b := temp;
end;
Result := temp;
end;
function MinutesToDaysHoursMinutes(AMinutes: Integer): string;
const
HOURSPERDAY = 8; // wieviele Stunden hat der Tag? (Beispiel hier: 1 Arbeitstag)
var
Days: Integer;
Hours: Integer;
Minutes: Integer;
begin
if (AMinutes > 0) then
begin
Hours := AMinutes div 60;
Minutes := AMinutes mod 60;
Days := Hours div HOURSPERDAY;
Hours := Hours mod HOURSPERDAY;
end
else
begin
Hours := 0;
Minutes := 0;
Days := 0;
end;
Result := Format('%.2d:%.2d:%.2d', [Days, Hours, Minutes]);
end;
function Distance(const x1, y1, x2, y2: Double): Double;
var
dx: Double;
dy: Double;
begin
dx := x2 - x1;
dy := y2 - y1;
Result := Sqrt(dx * dx + dy * dy);
end;
Function degress(nilai : Double) : Double;
begin
result := (180 / 3.14159265358979) * nilai;
End;
function GetRegDataType(const strRegPath, strRegValue: string): string;
var
s: string;
objRegistry: TRegistry;
begin
try
// creates the registru manager object
objRegistry := TRegistry.Create;
objRegistry.RootKey := HKEY_LOCAL_MACHINE;
// opens the specified key if exists
if objRegistry.OpenKey(strRegPath, false) then begin
case objRegistry.GetDataType(strRegValue) of
rdUnknown: s := 'Unknown';
rdString: s := 'String';
rdExpandString: s := 'ExpandString';
rdInteger: s := 'Integer';
rdBinary: s := 'Binary';
end;
end else
s := '(Can't get data type)';
finally
// destroys the registry manager object
objRegistry.Free;
end;
// set the return
result := s;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure ReadFromRegistry;
var
R : TRegistry;
begin
R := TRegistry.Create;
try
R.RootKey := HKEY_CURRENT_USER;
if R.OpenKey('\Software\fdehell\srf', True) then
begin
Form1.left:=R.ReadInteger('left');
Form1.top:=R.ReadInteger('top');
Form1.height:=R.ReadInteger('height');
Form1.width:=R.ReadInteger('width');
end;
Finally
R.CloseKey;
R.Free;
end;
end;
procedure WriteToRegistry;
var
R : TRegistry;
begin
R := TRegistry.Create;
try
R.RootKey := HKEY_CURRENT_USER;
if R.OpenKey('\Software\fdehell\srf', True) then
R.WriteInteger('left',Form1.Left);
R.WriteInteger('top',Form1.Top);
R.WriteInteger('height', Form1.Height);
R.WriteInteger('width', Form1.Width);
Finally
R.CloseKey;
R.Free;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
R : TRegistry;
begin
R := TRegistry.Create;
try
R.RootKey := HKEY_CURRENT_USER;
if R.OpenKey('\Software\fdehell\srf', True) then
R.WriteInteger('left',Form1.Left);
R.WriteInteger('top',Form1.Top);
R.WriteInteger('height', Form1.Height);
R.WriteInteger('width', Form1.Width);
Finally
R.CloseKey;
R.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ReadFromRegistry;
end;
procedure TForm1.FormClick(Sender: TObject);
var
AppName : PChar;
begin
AppName := PChar( Application.ExeName );
ShellExecute( Handle, 'open', AppName, nil, nil, SW_SHOWNORMAL );
close;
end;
end.
uses WinSpool; ... procedure TForm1.Button1Click(Sender: TObject); var NewDevMode: TDeviceModeA; MyDir: PChar; Int: Integer; begin GetMem(MyDir, 500); GetPrinterDriverDirectory(nil, nil, 1, MyDir, 200, Int); Label1.Caption:=StrPas(MyDir); FreeMem(MyDir); end;
uses
Printers;
function GetPixelsPerInchX: Integer;
begin
Result := GetDeviceCaps(Printer.Handle, LOGPIXELSX)
end;
function GetPixelsPerInchY: Integer;
begin
Result := GetDeviceCaps(Printer.Handle, LOGPIXELSY)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := Format('x: %d y: %d DPI (dots per inch)',
[GetPixelsPerInchX, GetPixelsPerInchY]);
end;
var strIni: array[0..MAX_PATH] of Char; arrWindows: array[0..64] of Char; begin GetWindowsDirectory(strIni, SizeOf(strIni)); StrCat(strIni, '\win.ini'); with TIniFile.Create(strIni) do try WriteString('windows', 'device', 'HP LaserJet 4 Plus,HPPCL5MS,LPT1:'); finally Free; end; StrCopy(arrWindows, 'windows'); SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@arrWindows)); end;
uses
Printers, Messages;
function GetDefaultPrinter: string;
var
ResStr: array[0..255] of Char;
begin
GetProfileString('Windows', 'device', '', ResStr, 255);
Result := StrPas(ResStr);
end;
procedure SetDefaultPrinter1(NewDefPrinter: string);
var
ResStr: array[0..255] of Char;
begin
StrPCopy(ResStr, NewdefPrinter);
WriteProfileString('windows', 'device', ResStr);
StrCopy(ResStr, 'windows');
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Longint(@ResStr));
end;
procedure SetDefaultPrinter2(PrinterName: string);
var
I: Integer;
Device: PChar;
Driver: PChar;
Port: PChar;
HdeviceMode: THandle;
aPrinter: TPrinter;
begin
Printer.PrinterIndex := -1;
GetMem(Device, 255);
GetMem(Driver, 255);
GetMem(Port, 255);
aPrinter := TPrinter.Create;
try
for I := 0 to Printer.Printers.Count - 1 do
begin
if Printer.Printers = PrinterName then
begin
aprinter.PrinterIndex := i;
aPrinter.getprinter(device, driver, port, HdeviceMode);
StrCat(Device, ',');
StrCat(Device, Driver);
StrCat(Device, Port);
WriteProfileString('windows', 'device', Device);
StrCopy(Device, 'windows');
SendMessage(HWND_BROADCAST, WM_WININICHANGE,
0, Longint(@Device));
end;
end;
finally
aPrinter.Free;
end;
FreeMem(Device, 255);
FreeMem(Driver, 255);
FreeMem(Port, 255);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetDefaultPrinter2;
end;
//Fill the combobox with all available printers
procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Items.Clear;
Combobox1.Items.AddStrings(Printer.Printers);
end;
//Set the selected printer in the combobox as default printer
procedure TForm1.Button2Click(Sender: TObject);
begin
SetDefaultPrinter(Combobox1.Text);
end;