procedure SetButtonStyle(Button : TButton); const BS_MASK = $000F; var Style: Word; I : Integer; begin Style := BS_PUSHBUTTON;
for i:= 0 to Form1.ComponentCount-1 do begin if Form1.Components[i] is TButton then if GetWindowLong(TButton(Form1.Components[i]).Handle, GWL_STYLE) and BS_MASK <> Style then SendMessage(TButton(Form1.Components[i]).Handle, BM_SETSTYLE, Style, 1); end;
If Button = nil then exit;
if Button.HandleAllocated then begin Style := BS_DEFPUSHBUTTON; if GetWindowLong(Button.Handle, GWL_STYLE) and BS_MASK <> Style then SendMessage(Button.Handle, BM_SETSTYLE, Style, 1); end; end;
procedure TForm1.Button23Click(Sender: TObject); begin ListBox1.Items.Strings[0] := \'0\'; tmpResult :=0; isResult := False; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button1Click(Sender: TObject); var s : String; begin S:= ListBox1.Items.Strings[0];
If (not isResult) AND (S <> \'0\') then S := S + (Sender as TButton).Caption else begin S := (Sender as TButton).Caption; isResult := False; end; ListBox1.Items.Strings[0] := s; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.FormCreate(Sender: TObject); begin IsResult := True; KeyPreview := True; (* If KeyPreview is True, keyboard events occur on the form before they occur on the active control. (The active control is specified by the ActiveControl property.)
If KeyPreview is False, keyboard events occur only on the active control.
Navigation keys (Tab, BackTab, the arrow keys, and so on) are unaffected by KeyPreview because they do not generate keyboard events.
KeyPreview is False by default. *) LastAction := _None; ListBox1.Items.Add(\'0\'); ListBox1.Style := lbOwnerDrawFixed; (* Owner-draw list boxes require more programming because the application needs information on how to render the image for each item in the list.
Each time an item is displayed in an lbOwnerDrawFixed list box, the OnDrawItem event occurs. The event handler for OnDrawItem draws the specified item.
The ItemHeight property determines the height of each of the items. *) end;
procedure TForm1.Button21Click(Sender: TObject); var s : String; begin if IsResult then Exit; S:= ListBox1.Items.Strings[0]; Delete(s,Length(s),1); ListBox1.Items.Strings[0] := s;
If ListBox1.Items.Strings[0] = \'\' then ListBox1.Items.Strings[0] := \'0\';
SetButtonStyle((Sender as TButton)); //Delete the ciffer at the end end;
procedure TForm1.FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean); begin Resize := False; //Prevent the user from rezing the application end;
procedure TForm1.Button27Click(Sender: TObject); begin Memory := Memory + StrToFloat(ListBox1.Items.Strings[0]); PostMessage(Handle, WM_UPDATE_MEMORY, 0, 0); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button26Click(Sender: TObject); begin Memory := Memory - StrToFloat(ListBox1.Items.Strings[0]); PostMessage(Handle, WM_UPDATE_MEMORY, 0, 0); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button24Click(Sender: TObject); begin Memory := 0; PostMessage(Handle, WM_UPDATE_MEMORY, 0, 0); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button25Click(Sender: TObject); begin ListBox1.Items.Strings[0] := FloatToStr(Memory); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.UpdateMemory(var Msg: TMessage); begin if Memory <> 0 then Panel1.Caption := \'M+\' else Panel1.Caption := \'\'; end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Panel1.SetFocus; case KEY of 96, 48 : Button1Click(Button16); 97, 49 : Button1Click(Button1); 98, 50 : Button1Click(Button2); 99, 51 : Button1Click(Button3); 100, 52 : Button1Click(Button4); 101, 53 : Button1Click(Button5); 102, 54 : Button1Click(Button6); 103, 55 : Button1Click(Button7); 104, 56 : Button1Click(Button8); 105, 57 : Button1Click(Button9); 8 : Button21Click(Button21); 77 : Button27Click(Button27); 67 : Button23Click(Button23); 111 : Button10Click(Button10); 106 : Button11Click(Button11); 109 : Button12Click(Button12); 107 : Button13Click(Button13); 110 : Button14Click(Button14); 13 : Button17Click(Button17); end; (* NUM 0 96 MUN 9 105 ENTER 13 NORMAL 0 48 NORMAL 9 57 BACKSPACE 8 M 77 C 67 NUM / 111 NUM * 106 NUM - 109 NUM + 107 NUM . 110 *) (* USE this to get hold of the value of the key pressed Caption := IntToStr(key); *) end;
procedure TForm1.Button10Click(Sender: TObject); begin isResult := true; tmpResult := StrToFloat(ListBox1.Items.Strings[0]); LastAction := _DIV; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button11Click(Sender: TObject); begin isResult := true; tmpResult := StrToFloat(ListBox1.Items.Strings[0]); LastAction := _MUL; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button12Click(Sender: TObject); begin isResult := true; tmpResult := StrToFloat(ListBox1.Items.Strings[0]); LastAction := _Sub; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button13Click(Sender: TObject); begin isResult := true; tmpResult := StrToFloat(ListBox1.Items.Strings[0]); LastAction := _Add; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button17Click(Sender: TObject); var Result : real; begin Case LastAction Of _Add : begin Result := tmpResult + StrToFloat(ListBox1.Items.Strings[0]); end; _Sub : begin Result := tmpResult - StrToFloat(ListBox1.Items.Strings[0]); end; _MUL : begin Result := tmpResult * StrToFloat(ListBox1.Items.Strings[0]); end; _DIV : begin Result := tmpResult / StrToFloat(ListBox1.Items.Strings[0]); end; else Result := StrToFloat(ListBox1.Items.Strings[0]); end;
ListBox1.Items.Strings[0] := FloatToStr(Result); isResult := True; SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button14Click(Sender: TObject); begin if isResult then Button23Click(Button23);
if Pos(#46, ListBox1.Items.Strings[0]) = 0 then ListBox1.Items.Strings[0] := ListBox1.Items.Strings[0] + \'.\';
SetButtonStyle((Sender as TButton)); (* Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos ignores case-insensitive matches. If Substr is not found, Pos returns zero. *) end;
procedure TForm1.Button15Click(Sender: TObject); begin ListBox1.Items.Strings[0] := FloatToStr(StrToFloat(ListBox1.Items.Strings[0]) * -1); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button18Click(Sender: TObject); begin ListBox1.Items.Strings[0] := FloatToStr(1/StrToFloat(ListBox1.Items.Strings[0])); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Button20Click(Sender: TObject); begin If StrToFloat(ListBox1.Items.Strings[0]) < 0 then Exit;
ListBox1.Items.Strings[0] := FloatToStr(Sqrt(StrToFloat(ListBox1.Items.Strings[0]))); SetButtonStyle((Sender as TButton)); end;
procedure TForm1.Timer1Timer(Sender: TObject); begin SetButtonStyle(nil); end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin with Control as TListbox do begin Canvas.Font.Name := \'Book Man OldStyle\'; Canvas.Font.Size := 15; Canvas.FillRect(Rect); if StrToFloat(ListBox1.Items.Strings[0]) < 0 then begin Canvas.Font.Color := clRed; Canvas.Font.Style:=Canvas.Font.Style+[fsBold]; end; Canvas.TextOut(Rect.Left, Rect.Top, Listbox1.Items[Index]); end; end;
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.