You are not logged in.
I have more good news for you!
In the latest development version I've added two new functions:
function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
function WideInputQuery(const ACaption, APrompt: WideString; var Value: WideString): Boolean;They work exactly like InputBox/WideInputBox, but they will also return TRUE is user presses OK, and FALSE when user presses CANCEL.
function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
function InputBox(const ACaption, APrompt, ADefault: String): String;
Hi Denis, many thanks for that.
> but they will also return
You mean also as in as addition?
But how can InputQuery be the same as InputBox? Since InputQuery is boolean?
If i have:
var
test, default : string;
begin
default := 'defaultstring';
test := InputQuery('Title', 'Prompt', default);
IF test = False exit;
end;
I get an type mismatch of course due string <> boolean.
I expect InputQuery should be of type string as InputBox()
but return string 'False' if user press cancel,
otherwise the value of the input box.
Best would be if InputBox() had this Cancel='False' feature itself.
And for boolean we have now DialogYesNo http://www.den4b.com/forum/viewtopic.php?pid=1892#p1892
All the same for WideXxxx of course.
-----------
And also InputQuery ask for an var as third parameter..... why not an string too like with InputBox?
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
var
test, default : string;begin
default := 'defaultstring';
test := InputQuery('Title', 'Prompt', default);
IF test = False exit;
end;
Just make test a boolean:
test : boolean;
default : string;
And also InputQuery ask for an var as third parameter..... why not an string too like with InputBox?
Functions may return only one parameter by itself. So InputQuery returns to you with true if OK was pressed and false if CANCEL was pressed. Boolean is better for that job than string as it is safer and quicker.
But you need two things in return. The main one is the second one (user input) and this is returned by modification of var Value: string. If there were a simple String in InputQuery, function wouldn't be able to modify it and return user input back to you.
So using of input query is like this:
var
test : boolean;
default : string;
begin
Value := 'defaultstring';
test := InputQuery('Title', 'Prompt', Value);
IF test = False then exit
ELSE FileName = Value;
end.
or even shorten
var
default : string;
begin
Value := 'defaultstring';
IF InputQuery('Title', 'Prompt', Value) = False then exit
ELSE FileName = Value;
end.
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline
And also InputQuery ask for an var as third parameter..... why not an string too like with InputBox?
The third parameter is an var because it is re-filled with new user-input for later use?
It's an trick, because Function can return one thing only, not CheckButton-Bool AND UserInput-String the same time?
I imaging that i understood (not sure), thank krtek.
var
PressedButton: boolean;
UserInput: string;
begin
FilePath := '';
UserInput := 'defaultstring';
PressedButton := InputQuery('Title', 'Prompt', UserInput);
//if PressedButton=True then OK was pressed, if False then Cancel was pressed.
IF (PressedButton = False) Then
begin
WideShowMessage('Cancel pressed');
exit;
end;
IF (UserInput = '') Then
WideShowMessage('Empty string!')
ELSE
FileName := UserInput + WideExtractFileExt(FileName);
end.
Last edited by Stefan (2009-08-12 18:13)
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Yeah, I think you've got it.
In your example you can even drop the PressedButton variable cause IF-ELSE clause can simply take the value returned by InputQuery:
IF not InputQuery('Title', 'Prompt', UserInput) Then exit
ELSE FileName := UserInput + WideExtractFileExt(FileName);
Generally they say that it's better not to compare booleans to true/false, but to use syntax:
If PressedButton then ... (which is an equivalent of If (PressedButton = true) then ...)
If not PressedButton then ... (which is an equivalent of If (PressedButton = false) then ...)
You can see this syntax above...
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline