~ubuntu-branches/ubuntu/trusty/mricron/trusty-proposed

« back to all changes in this revision

Viewing changes to common/dialogsx.pas

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-07-29 22:07:43 UTC
  • Revision ID: james.westby@ubuntu.com-20100729220743-q621ts2zj806gu0n
Tags: upstream-0.20100725.1~dfsg.1
ImportĀ upstreamĀ versionĀ 0.20100725.1~dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit dialogsx;
 
2
{$Include isgui.inc}
 
3
{$H+}
 
4
interface
 
5
uses
 
6
 
 
7
SysUtils,IniFiles;   
 
8
                                      
 
9
type
 
10
  TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp);
 
11
  TMsgDlgButtons = set of TMsgDlgBtn;
 
12
  TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
 
13
 
 
14
procedure Msg (lStr: string);
 
15
procedure ShowMsg (lStr: string);
 
16
procedure msgfx (a,b,c,d: double); overload; //fx used to help debugging - reports number values
 
17
function MsgDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
 
18
function GetInt(lStr: string; lMin,lDefault,lMax: integer): integer;
 
19
procedure MyReadLn;//no GUI: waits for user
 
20
function GetStr(lPrompt: string): string;
 
21
//procedure vx (a,b,c,d: double); 
 
22
 
 
23
const
 
24
 mrCancel = 2;
 
25
 mrAbort = 1;// idAbort
 
26
 mrNo = 0;
 
27
implementation
 
28
{$IFDEF GUI}uses readint,dialogs,gui; {$ENDIF}
 
29
 
 
30
procedure vx (a,b,c,d: double);  //vx used to help debugging - reports number values
 
31
begin
 
32
        msg(floattostr(a)+':'+floattostr(b)+':'+floattostr(c)+':'+floattostr(d));
 
33
end;
 
34
 
 
35
 
 
36
procedure MyReadLn;
 
37
{$IFDEF GUI}
 
38
begin
 
39
  //do nothing
 
40
end;
 
41
{$ELSE}
 
42
begin
 
43
  {$IFNDEF UNIX}
 
44
 if IsConsole then
 
45
                ReadLn;
 
46
   {$ENDIF}
 
47
end;
 
48
{$ENDIF}
 
49
 
 
50
function MsgDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
 
51
{$IFDEF GUI}
 
52
var
 
53
   lDlgType : Dialogs.TMsgDlgType;
 
54
   lButtons: Dialogs.TMsgDlgButtons;
 
55
 
 
56
begin
 
57
  lDlgType :=  Dialogs.TMsgDlgType(DlgType);
 
58
  lButtons:= Dialogs.TMsgDlgButtons(Buttons);
 
59
  result := MessageDlg(Msg, lDlgType, lButtons,HelpCtx);
 
60
{$ELSE}
 
61
begin
 
62
  result := 0;
 
63
  writeln('WARNING: dialogs not being used. Unabled to process this '+Msg);
 
64
{$ENDIF}
 
65
end;
 
66
 
 
67
procedure ShowMsg (lStr: string);
 
68
begin
 
69
{$IFDEF GUI}
 
70
         ShowMessage(lStr);
 
71
{$ELSE}
 
72
        writeln(lStr)
 
73
{$ENDIF}
 
74
end;
 
75
procedure msgfx (a,b,c,d: double); overload; //fx used to help debugging - reports number values
 
76
begin
 
77
    {$IFDEF GUI}
 
78
        msg(floattostr(a)+'x'+floattostr(b)+'x'+floattostr(c)+'x'+floattostr(d));
 
79
    {$ELSE}
 
80
        msg(floattostr(a)+'x'+floattostr(b)+'x'+floattostr(c)+'x'+floattostr(d));
 
81
    {$ENDIF}
 
82
end;
 
83
 
 
84
procedure Msg (lStr: string);
 
85
begin
 
86
{$IFDEF GUI}
 
87
         MainForm.Memo1.Lines.Add(lStr);
 
88
         MainForm.refresh;
 
89
{$ELSE}
 
90
        writeln(lStr)
 
91
{$ENDIF}
 
92
end;
 
93
 
 
94
function GetStr(lPrompt: string): string;
 
95
{$IFDEF GUI}
 
96
var
 
97
   lOK: boolean;
 
98
begin
 
99
    lOK := InputQuery(lPrompt, lPrompt, result);
 
100
    if not lOK then
 
101
       result := '';
 
102
end;
 
103
{$ELSE}
 
104
var
 
105
   lS: string;
 
106
begin
 
107
      writeln ( lPrompt);
 
108
      readln(lS);
 
109
      result := lS;
 
110
end;
 
111
{$ENDIF}
 
112
 
 
113
function GetInt(lStr: string; lMin,lDefault,lMax: integer): integer;
 
114
{$IFDEF GUI}
 
115
begin
 
116
    //result := GetInt(lStr, lMin,lDefault,lMax);
 
117
    result := lDefault;
 
118
    Showmessage('Warning - unable to get values for '+lStr);
 
119
end;
 
120
{$ELSE}
 
121
var
 
122
   lS: string;
 
123
   lError,lI: integer;
 
124
begin
 
125
      writeln ( lStr+' ['+inttostr(lMin)+'..'+inttostr(lMax)+'], default '+inttostr(lDefault));
 
126
      readln(lS);
 
127
      Val(lS,lI,lError);
 
128
      if lError = 0 then
 
129
         result  := round(lI)
 
130
      else begin
 
131
          writeln(inttostr(lDefault));
 
132
          result := lDefault;
 
133
      end;
 
134
      if result < lMin then
 
135
         result := lMin;
 
136
      if result > lMax then
 
137
         result := lMax;
 
138
end;
 
139
{$ENDIF}
 
140
 
 
141
 
 
142
end.
 
143