Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Delphi: How can I build a command Line within a GUI Application?

Posted on 2009-04-20
9
Medium Priority
?
648 Views
Last Modified: 2013-11-23
I am trying to figure out how to do a command line interface Within a Standard GUI application in delphi.

I tried using a Memo Component but I dont know really what I am doing and googling is wearing me out.
0
Comment
Question by:jamerslong
  • 7
  • 2
9 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24197828
basically a command line let's you type text and not move the actual cursor
when you hit enter it processes the command last typed.

the difference with a memo is that it let's you move the cursor ...

have you got any code so far ?
0
 
LVL 4

Author Comment

by:jamerslong
ID: 24200421
So far, Backspace and Enter keys, My problem thus far is preventing certin inputs (moving cursor and selecting text)
havent really done much as my kid is still in the hospital for Jaundice....


procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #08 then //Backspace
  begin
  if Inputs = 0 then
    Key := #0 //Stop keypress
  else
    Inputs := Inputs -1;
end
else
  begin
  Inputs := Inputs +1;//allow Keypress and add allowed backspaces.
  end;
if Key = #13 then //If user presses enter key
  begin
  Inputs := 0;
  end
end;

Open in new window

0
 
LVL 4

Author Comment

by:jamerslong
ID: 24200450
Also OnKeyPress is when this is being done, How do I post process? E.G.

if Key = #13 then //If user presses enter key
  begin
  Memo1.Text := Memo1.Text + 'Testing $: ';
  Memo1.SelStart := Memo1.GetTextLen;
  Inputs := 0;
  end
This Adds the Testing&: Before the New Line is added, how can I do this after the new line is added?

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Author Comment

by:jamerslong
ID: 24200515
I did this instead...
if Key = #13 then
begin
  Memo1.Lines.Add('Testing $: ');
  Memo1.SelStart := Memo1.GetTextLen;
  Inputs := 0;
  Key := #0;
  end;

Open in new window

0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 2000 total points
ID: 24201453
i think you need some processing in the OnKeyDown,
a private var to keep track of the first char entered,
and processing in the OnKeyPress

- in the OnKeyDown, i would allways reset the caret to the end of the memo
- the private var would be the length of the text before any typing is done
- the onkeypress just catches the enter

fCaretStart := Length(Memo1.Text);

after Enter:
aCurrentLength := Length(Memo1.Text);
TextTyped := Copy(Memo1.Text, fCaretStart, aCurrentLength); // Copies the actual text typed or pasted

then process TextTyped -> you will need some parser to extract the commands and parameters
example : dir
-> list files to Memo1 -> GetCurrentDirList(List);
Memo1.Lines.AddStrings(List);

after a command is processed:
Memo1.Lines.Add('prompt>');
fCaretStart := Length(Memo1.Text);

and then let the user at it again
 this is just pseudo code, but this is only an idea
0
 
LVL 4

Author Comment

by:jamerslong
ID: 24207450
processing it is going to be a different subject, It will be used for building a custom SQL table. the problem I was having was preventing a user from selecting text and moving the carat beond the typing area they are supposed to be using.  I tried stopping the char press of the up button, I think I will try using the keypreview to check the arrow keys before they make it to the text box.

I wonder if there is some kind of transparent panel I could put over the Memo to prevent a user from using the mouse.
0
 
LVL 4

Author Comment

by:jamerslong
ID: 24211582
I figured out how to control Char movement with mouse and keyboard with a timer :) that works great, now i have to figure the best way to extract the command text?
0
 
LVL 4

Author Comment

by:jamerslong
ID: 24211588
nevermind i see you posted it already
0
 
LVL 4

Author Comment

by:jamerslong
ID: 24211830
things are progressing quite nicely, but one issue... I cannot capture the Delete key Any Ideas?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question