Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.06.24;
Скачать: CL | DM;

Вниз

InputQuery   Найти похожие ветки 

 
SysError ©   (2006-11-13 21:55) [0]

Скажите пожалуйста, есит ли в KOL функция сходная со значением InputQuery в VCL? Заранее спасибо!


 
_gandalf_   (2006-11-14 11:37) [1]

Что нить в таком духе можно попробовать
unit InputBox2;

interface

uses
 KOL,Windows,Messages;

function inputbox(caption:string;findtext:string; password:boolean):string;

implementation

type
 TInputBoxForm=object(TObj)
   Form:PControl;
   Edit:PControl;
   Button:PControl;
   Text:String;
 end;

var
 ResultText:String;

{$DEFINE TEST_SHOWMODAL}

function inputbox(caption:string;findtext:string; password:boolean):string;
var forma,
   edit,
   button:PControl;
   text:string;

procedure click(Forma : PControl; Sender : PObj );
begin
 ResultText:=forma.Children[0].Text;
 forma.ModalResult:=1;
end;

procedure close(Forma : PControl; Sender : PObj );
begin
 ResultText:="";
 forma.ModalResult:=1;
end;

begin
 forma:=NewForm(applet, caption );
 forma.Style:= WS_BORDER or WS_SYSMENU or WS_VISIBLE;;
if password then
   edit:=neweditbox(forma,[eoPassword]).Size(180,22)
else
   edit:=neweditbox(forma,[]).Size(180,22);  edit.Left:=20;edit.Top:=20;edit.Color:=clwhite;
 edit.Text:=findtext;
 button:=newbutton(forma,"Ok").Size(55,22);
 button.Left:=215;
 button.Top:=20;
 button.OnClick:=TOnEvent(Makemethod(forma,@click));
 forma.Height:=110;
 forma.Width:=280;
 forma.CenterOnParent;
 forma.OnClose:=TOnEventAccept(Makemethod(forma,@close));
 forma.ShowModal;
 result:=ResultText;
 forma.Close;
end;

end.


 
MTsv DN ©   (2006-11-14 12:20) [2]

> procedure click(Dummy : Pointer; Forma : PControl; Sender : PObj );
> procedure close(Dummy : Pointer; Forma : PControl; Sender : PObj );

Добавить выделенное жирным шрифтом....


 
_gandalf_   (2006-11-14 13:08) [3]

или в кол чтото координально поменялось, или я облажался - Forma : PControl; это и есть тот Dummy


 
MTsv DN ©   (2006-11-14 14:01) [4]

> или в кол чтото координально поменялось, или я облажался - Forma : PControl; это и есть тот Dummy
Сорри, Гэндальф... Это я не подумавши ляпнул...


 
SysError ©   (2006-11-14 18:58) [5]

Еще раз спасибо! Не плохо было бы добавить такую функцию в KOL.pas


 
thaddy   (2006-11-14 20:29) [6]

I posted this about three years ago.
Note this actually makes your program larger than using pure KOL, but it is a true API style input query:

program kolinputquery;

uses
Windows,
Messages,
Kol;
{$R *.res}
Function ApiInputBox( Const Caption, Prompt, Default: String ): String;forward;
Function ApiInputQuery( Const Caption, Prompt: String; Var value: String ):Boolean;forward;
const
 INPUT_DIALOG =   1;
 IDC_EDIT     =   102;
 IDC_LABEL    =   101;
resourcestring
 DefaultAPIQueryCaption = "Enter data";
 DefaultAPIQueryPrompt  = "Value:";

Type
 TInputBoxData = Record
   aCaption, aPrompt, aValue: String;
 End;
 PInputBoxData = ^TInputBoxData;

Function ApiInputBox( Const Caption, Prompt, Default: String ): String;
 Var
   value: String;
 Begin
   value:= Default;
   If APIInputQuery( Caption,Prompt, Value ) Then
     Result := value
   Else
     Result := Default;
 End; { ApiInputBox }

Function DlgProc( hwndDlg: HWND; Msg: UINT; wparam: WPARAM; lparam: LPARAM ):
BOOL; stdcall;
 Procedure InitDialog;
   Var
     pdata: PInputBoxData;
   Begin
     Assert( lparam <> 0 );
     pdata := Pointer( lparam );
     SetWindowLong( hwndDlg, GWL_USERDATA, lparam );
     SetWindowText( hwndDlg, PChar( pdata^.aCaption ));
     SetDlgItemText( hwndDlg, IDC_LABEL, Pchar( pdata^.aPrompt ));
     If Length( pdata^.aValue ) > 0 Then
       SetDlgItemText( hwndDlg, IDC_EDIT, Pchar( pdata^.aValue ));
     SetFocus( GetDlgItem( hwndDlg, IDC_EDIT ));
   End; { InitDialog }

 Function HandleCommand: Boolean;
   Var
     pdata: PInputBoxData;
   Begin
     Result := False;
     If  HiWord( wparam ) = BN_CLICKED Then Begin
       Result := true;
       If LoWord( wparam ) = IDOK Then Begin
         pData := Pointer( GetWindowLong( hwndDlg, GWL_USERDATA ));
         SetLength( pData.aValue,
                    SendDlgItemMessage(
                      hwndDlg, IDC_EDIT,
                      WM_GETTEXTLENGTH, 0, 0 ));
         GetDlgItemText( hwndDlg, IDC_EDIT, Pchar(pData.aValue),
                         Length( pData.aValue )+1 );
       End;
       EndDialog( hwndDlg, LoWord( wparam ));
     End;
   End; { HandleCommand }

 Begin
   Result := False;
   Case Msg Of
     WM_INITDIALOG: InitDialog;
     WM_COMMAND   : Result :=  HandleCommand;
   End; { Case }
 End; { DlgProc }

Function ApiInputQuery( Const Caption, Prompt: String; Var value: String ):Boolean;
 Var
   data: TInputBoxData;
   res: Integer;
 Begin
   If Length( Caption ) > 0 Then
     data.aCaption:= Caption
   Else
     data.aCaption := DefaultAPIQueryCaption;

   If Length( Prompt ) > 0 Then
     data.aPrompt := Prompt
   Else
     data.aPrompt := DefaultAPIQueryPrompt;

   data.aValue  := value;
   res := DialogBoxParam( hInstance, MakeIntResource( INPUT_DIALOG ),
                          GetActiveWindow, @DlgProc, LPARAM(@data ));
   Result := res = IDOK;
   Assert( res <> -1, "ApiInputQuery: DialogBoxParam failed" );
 End; { ApiInputQuery }

 var a:string;
begin
 a:="Thaddy";
Applet:=NewForm(nil,"");
Applet.Caption:= ApiInputBox("","",A);//then Applet.Caption:=A;
Run(Applet)
end.

Copy the following to a file apidlg.rc and compile it with brcc32:

/****************************************************************************
apidlg.rc
produced by Borland Resource Workshop
*****************************************************************************/

#define INPUT_DIALOG   1
#define IDC_EDIT   102
#define IDC_LABEL  101

INPUT_DIALOG DIALOG 6, 15, 207, 45
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "INPUTDIALOG"
FONT 8, "MS Sans Serif"
{
DEFPUSHBUTTON "OK", IDOK, 148, 6, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 148, 24, 50, 14
LTEXT "Label 1", IDC_LABEL, 4, 12, 138, 8
EDITTEXT IDC_EDIT, 4, 25, 138, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
}




Страницы: 1 вся ветка

Текущий архив: 2007.06.24;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.018 c
15-1180508378
pasha_golub
2007-05-30 10:59
2007.06.24
В Англии удалено упоминание холокоста...


15-1179990326
Pazitron_Brain
2007-05-24 11:05
2007.06.24
Ценителям советской аудиотехники


2-1180782287
зыбыл ник%)
2007-06-02 15:04
2007.06.24
Анимация сворачивания в Висте


15-1179892477
db2admin
2007-05-23 07:54
2007.06.24
RiData


11-1163128856
SKA1997
2006-11-10 06:20
2007.06.24
ALT + TAB