Wednesday, 5 May 2010

Text Area Code Generator

In this first project, we're going to create an application that can generate HTML codes to create a text area. First you have to create a form like the picture below :

Now, write the codes for each event of the components :

When the first time we run the program, we set the default values of some component's properties. So we write some codes on FormActivate event of Form1 :

  procedure TForm1.FormActivate(Sender: TObject);
  begin
   Memo1.Text := '';
   Memo2.Text := '';
   Memo2.SetFocus;
   Edit1.Enabled := false;
   Edit2.Enabled := false;
   Edit3.Enabled := false;
   RadioButton1.Checked := true;
   RadioButton2.Checked := false;
   RadioGroup1.ItemIndex := 0;
   Edit4.Text := '1';
   Edit5.Text := '1';
  end;

The codes for RadioButtons ( Text Only and Link Codes ) :

  procedure TForm1.RadioButton1Click(Sender: TObject);
  begin
   Edit1.Enabled := false;
   Edit2.Enabled := false;
   Edit3.Enabled := false;
   Memo2.Enabled := true;
   Memo2.SetFocus;
  end;

  procedure TForm1.RadioButton2Click(Sender: TObject);
  begin
   Edit1.Enabled := true;
   Edit2.Enabled := true;
   Edit3.Enabled := true;
   Memo2.Enabled := false;
   Edit1.SetFocus;
  end;

We need to limit the input of rows and columns for numeric inputs only :

  procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
  begin
   if not (key in ['0'..'9', #8]) then key := #0;
  end;

  procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char);
  begin
   if not (key in ['0'..'9', #8]) then key := #0;
  end;


And the other codes for the events of the rest components are :


procedure TForm1.GenerateButtonClick(Sender: TObject);

var

 LinkBanner : string;

begin

 if RadioButton1.Checked then

  begin

   memo1.Text :='<p align="'+RadioGroup1.Items.String

                [RadioGroup1.ItemIndex]+'"><textarea name="code" rows="' + 

                Edit4.Text + '"  cols="' +Edit5.Text + '">' + memo2.Text  + 

                '</textarea></p>';                                  

  end else

  begin

   LinkBanner := '<a href="' + Edit2.Text +

                 '"target="_blank"><img src="'+Edit1.Text +

                 '" border="0" alt="' + Edit3.Text + '" /></a>';

   memo1.Text := RadioGroup1.Items.Strings[RadioGroup1.ItemIndex] + 

                 '"><textarea name="code" rows="' +           

                 Edit4.Text + '" cols="'+Edit5.Text + '">' + LinkBanner +

                 '</textarea></p>';

  end;

end;



procedure TForm1.ClearButtonClick(Sender: TObject);

begin
  memo1.Text := '';

end;


procedure TForm1.ExitButtonClick(Sender: TObject);
begin
  Application.Terminate;
end;

To see the complete codes you can download this project here.

9 comments:

  1. mungkin ini yang digunakan untuk menampilkan kode script dalam postingan

    semoga sukses selalu kawan

    ReplyDelete
  2. nanti saya kasih buat temen saya yang jadi asdos delpi :)

    ReplyDelete
  3. @Pakde : yes, it's true, we can create a text area that contains some HTML codes to be posted.
    @Secangkir.. : thank you.. you can download this project and give to your friend.. :)

    ReplyDelete
  4. wah buat parse kode untuk diposting ini ya ?

    ReplyDelete
  5. numpang download ya, siapa tau nanti kepake..

    ReplyDelete
  6. very helpfull , thank for share

    ReplyDelete
  7. @Artikel : yuup, that's right
    @Dimas : Ok, thanks
    @big ribbon : you're welcome :)

    ReplyDelete
  8. langsung download ...
    salam kenal jg sob
    jangan lupa mampir lg OK

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.