Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BBCoder tool available 7

Status
Not open for further replies.

Griffyn

Programmer
Jul 11, 2002
1,077
AU
Hi all,

I've made available the li'l tool I use to add syntax highlighting to my code examples. faq102-6487. (feel free to rate it highly) eg.
Code:
[b]procedure[/b] TMyClass.Whatever([b]var[/b] Param: Integer);
[b]var[/b]
  s : [b]String[/b];
  x : Real;
[b]begin[/b]
  [b]inherited[/b];   [navy]// call TBaseClass.Whatever[/navy]
  [b]if[/b] s = [teal]'text'[/teal] [b]then[/b]
    x := [purple]0.50[/purple];
[b]end[/b];

Now your posts can look as good as mine! [tongue] Seriously though, I think it really aids readability, particularly for large or complex code examples.

Download from here if you like For any issues with it, I can be contacted through the faq topic.
 
good work! star for you...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Code:
[b]procedure[/b] StarIdea;
const
  A = 'Griffyn, What a brilliant idea.';
  B = 'Wish I thought of it!';
  C = 'Thanks and a star for you';
[b]begin[/b]
  ShowMessage(A);
  ShowMessage(B);
  ShowMessage(C);
[b]end[/b];

Andrew
Hampshire, UK
 
Andrew, you need a break from programming - I do hope you'll be sitting away from your PC for at least some time over Christmas!!!

Nice one Griffyn!

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Code:
[b]function[/b] HolidayInstructions(stress: Boolean; tiredness: Boolean; obsession_with_programming: Boolean): [b]String[/b];
[b]begin[/b]
  [b]if[/b] (stress [b]and[/b] tiredness [b]and[/b] obsession_with_programming) [b]then[/b]
    Result := [teal]'Take a much needed break for a week or two!'[/teal]
  [b]else[/b]
    Result := [teal]'Do some work!'[/teal];
[b]end[/b];

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
From my posting above, I've noticed that const needs to be added to the list of reserved words. Fortunately, griffyn has implemented the list of reserved words as an editable text file so we can easily fix this oversight.

Okay, Clive. I'll take a break now!

Andrew
Hampshire, UK
 
Thanks guys. I've updated the zip file with const added to the reserved words, and replaced the example code in the program with a simple comment.
 
Updated again with a minor fix, some class reserved words (virtual, abstract, etc.) plus support for property reserved words (such as read, write, etc.)
 
Griffyn,

small suggestion: get rid of that ugly D7 icon.

[bigglasses]

it would we wonderful if you convert this into an IE plugin!

[peace]

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I would if I could. I've never done that before, and it sounds like an excellent first project. I've spent quite a while googling for info on Delphi, ActiveX controls, even Firefox extensions to try and get started. I've copied my code across into an 'Active Form' from the Delphi6, File, New, Other, ActiveX page. And that compiles ok and gives me an .OCX file.

I've registered it with [tt]regsvr32 bbcoderx.ocx[/tt] - but then what?

Ultimately it would be nice to be able to select some code in a edit box like at the bottom of this page, right-click and choose BBCoder from the pop-up menu, and have the selection changed to include the syntax highlighted code. No UI or anything, just select, right-click, left-click.

Can anyone help me with getting that far?
 
k, will look into that :)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
you can use the toolband example as a start:


download the above package.
toolband code is in the delphiband102.zip file under the demos dir.

//daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I was going to do that but I figured it would be easier to manage in a simple list. Plus - I figured if there's a config file, it makes little difference if there's more than one config file.
 
I've been playing around with this for a while, and I feel like I'm tantalisingly close. Can anyone help me here?

I've set up a BHO and have got it monitoring the BeforeNavigate2 event. My plan is that this proggy watches whenever you move to a new page, and if you're on tek-tips and on this forum and you're submitting something, the BHO scans the text, and runs the syntax highlighter over anything between [[]code] and [[]/code] so that any code examples are automatically highlighted.

This is where I'm stuck (I'm just logging at the moment):
Code:
[b]uses[/b]
  ActiveX;

[b]procedure[/b] TBBCoder.BeforeNavigate(Sender: TObject; [b]const[/b] pDisp: IDispatch; [b]var[/b] URL, Flags, TargetFrameName, PostData, Headers: OleVariant; [b]var[/b] Cancel: WordBool);
[b]var[/b]
  t : TextFile;
  ps : PSafeArray;
  p : PChar;
[b]begin[/b]
  ps := PSafeArray(@PostData);  [navy]// PostData is a SafeArray (or a pointer to one)[/navy]
  p := PChar(ps^.pvData);  [navy]// pvData is a pointer (I presume this element of TSafeArray is what I should be looking for)[/navy]
  AssignFile(t, [teal]'c:\temp.txt'[/teal]);
  Append(t);
  [b]try[/b]
    WriteLn(t, [teal]'----------- '[/teal] + DateTimeToStr(Now));
    WriteLn(t, URL);
    WriteLn(t, p);
  [b]finally[/b]
    CloseFile(t);
  [b]end[/b];

I've been playing around with everything I can think of to get text out of PostData, but it's either blank, or garbage.

I haven't given you enough to plug and play with, so I'm hoping someone has mucked around with SafeArrays being passed as an OLEVariant before?
 
Unfortunately that didn't help, but this page did. Good to know that I'm not the only one struggling with it.

If I was tantalising close before, I'm going crazy with it under my nose now. It's been slow going, coz I can't use the IDE debugger to help me out, it's been logging everywhere.

The code is grabbing the forum post, modifying it, and trying to reinsert the postdata back into the event, but that ain't happening. As far as I can tell, any changes I make to PostData are just being ignored, despite it being a var reference in the event header. I'll come back to it tomorrow, but post your thoughts anyone if you happen to know or find something that will tell me how to get over this last hurdle.
 
show us some code :)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
oh yeah, sure :)

Code:
[b]procedure[/b] TBBCoder.BeforeNavigate(Sender: TObject; [b]const[/b] pDisp: IDispatch;
  [b]var[/b] URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
  [b]var[/b] Cancel: WordBool);
[b]var[/b]
  c : Integer;
  pd : [b]String[/b];   [navy]// hold new postdata[/navy]
  pda : [b]array[/b] [b]of[/b] byte;  [navy]// to convert back to OleVariant[/navy]
[b]begin[/b]
  pd := [teal]''[/teal];
  [b]if[/b] [b]not[/b] (VarIsEmpty(PostData) [b]or[/b] (VarToStr(PostData) = [teal]''[/teal])) [b]then[/b]
    [b]for[/b] c := [purple]0[/purple] [b]to[/b] VarArrayHighBound(PostData, [purple]1[/purple]) - [purple]1[/purple] [b]do[/b]
      pd := pd + Chr(StrToInt(PostData[c]));
  [navy]// snip - do syntax highlighting bit, pd is now bbcode'ified[/navy]
  [b]if[/b] pd <> [teal]''[/teal] [b]then[/b]
  [b]begin[/b]
    VarArrayReDim(PostData, Length(pd));
    SetLength(pda, Length(pd));
    [b]for[/b] c := [purple]1[/purple] [b]to[/b] Length(pd) [b]do[/b]
      pda[c - [purple]1[/purple]] := Ord(pd[c]);
    PostData := pda;   [navy]// this should modify the data posted, but doesn't[/navy]
  [b]end[/b];
[b]end[/b];

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top