Shop OBEX P1 Docs P2 Docs Learn Events
Has anyone used the tokenizer with Dephi? — Parallax Forums

Has anyone used the tokenizer with Dephi?

ArchiverArchiver Posts: 46,084
edited 2003-04-18 06:23 in General Discussion
I'm using an ancient Delphi 2.0, and have gotten the Version and
TestRecAlignment functions to work, but I'm still stymied by the
Compile function.

Following the instructions in the "Using the PBASIC Tokenizer
Library" PDF file, I verified, via the TestRecAlignment function,
that my data structiure is aligned correctly.

The error I get is: Access violation at address 10001A61. Write of
address 00000005.

Here's my code:

const
EEPROMSize = 2048;

type
PModuleRec = ^TModuleRec;
TModuleRec = record
Succeeded : Boolean; (*Pass or failed on
compile*)
Error : PChar; (*Error message if
failed*)
DebugFlag : Boolean; (*Indicates there's
debug data*)

TargetModule : Byte; (*BASIC Stamp Module
to compile for. 0=None, 1=BS1, 2=BS2, 3=BS2e, 4=BS2sx, 5=BS2p,
6=BS2pe*)
TargetStart : Integer; (*Beginning of $STAMP
directive target, in source*)
ProjectFiles : array [noparse][[/noparse]1..7] of PChar; (*Paths and names of
related project files, if any*)
ProjectFilesStart : array [noparse][[/noparse]1..7] of Integer;(*Beginning of
project file name in source*)

Port : PChar; (*COM port to
download to*)
PortStart : Integer; (*Beginning of port
name in source*)

SourceSize : Integer; (*Enter actual source
code length here*)
ErrorStart : Integer; (*Beginning of error
in source*)
ErrorLength : Integer; (*Number of bytes in
error selection*)

EEPROM : array [noparse][[/noparse]1..EEPROMSize] of byte; (*Tokenized data if
compile worked*)
EEPROMFlags : array [noparse][[/noparse]1..EEPROMSize] of byte;(*EEPROM flags, bit
7: 0=unused, 1=used*)

(*bits 0..6: 0=empty, 1=undef data,
2=def data, 3=program*)

VarCounts : array [noparse][[/noparse]1..4] of byte; (*# of.. [noparse][[/noparse]0]=bits, [noparse][[/noparse]1]
=nibbles, [noparse][[/noparse]2]=bytes, [noparse][[/noparse]3]=words*)
PacketCount : Byte; (*# of packets*)
PacketBuffer : array [noparse][[/noparse]1..2304] of byte; (*packet data*)
end;

var
TokenizerTestForm: TTokenizerTestForm;
TokenizerVersion : Integer;


function Version: Integer pascal; external 'tokenizer.dll';
function TestRecAlignment(Rec : TModuleRec) : Boolean pascal;
external 'tokenizer.dll';
function Compile(Rec : TModuleRec;
Src : PChar;
DirectivesOnly : Boolean;
ParseStampDirective : Boolean) : Boolean pascal;
external 'tokenizer.dll';

var
TestRec : TModuleRec;

procedure TTokenizerTestForm.FormCreate(Sender: TObject);
var
SrcBuf : PChar;
begin
TokenizerVersion := Version();
Label1.Caption := Concat(Label1.Caption, Format('%4.2f',
[noparse][[/noparse]TokenizerVersion/100]));


if not TestRecAlignment(TestRec) then
ShowMessage('TestRecAlignment failed!')
else
ShowMessage('TestRecAlignment worked!');

SrcBuf := StrNew('''{$Stamp BS2} ''test'#$0D#$0A'debug
HI!'#$0D#$0A'outs=65535'#0);
ShowMessage(SrcBuf);

TestRec.SourceSize := StrLen(SrcBuf);
if not Compile(TestRec, SrcBuf, True, True) then // <---The error
occurs here.
ShowMessage('Compile failed!');
end;

end.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-18 02:45
    I figured out that my problem was that I was using the PASCAL
    directive when declaring the Compile() external function. (I had
    originally used it because that was the only way was I was able to
    get the TestRecAlignment function to work.)

    It turns out that STDCALL is the correct directive to use. When I
    originally tried it with TestRecAlignment, it failed because the
    entire TModuleRec was being passed on the stack. (With the Pascal
    calling convention, only a pointer is passed.)

    But the Compile() failed with the PASCAL directive because with
    Pascal calling convention, the parameters are pushed on the stack in
    order from left to right (instead of right to left as with STDCALL,)
    so tokenize.dll was trying to use the value of the
    ParseStampDirective Boolean as a pointer!

    So now I've gotten it to compile a simple program, but I have now
    discovered that it doesn't recognize the $PBasic directive! Does
    anyone know when Parallax will be releasing a PBASIC 2.5 version?

    Greg Ross



    --- In basicstamps@yahoogroups.com, "gwrosss" <GWR@P...> wrote:
    > I'm using an ancient Delphi 2.0, and have gotten the Version and
    > TestRecAlignment functions to work, but I'm still stymied by the
    > Compile function.
    >
    > Following the instructions in the "Using the PBASIC Tokenizer
    > Library" PDF file, I verified, via the TestRecAlignment function,
    > that my data structiure is aligned correctly.
    >
    > The error I get is: Access violation at address 10001A61. Write of
    > address 00000005.
    >
    > Here's my code:
    >
    > const
    > EEPROMSize = 2048;
    >
    > type
    > PModuleRec = ^TModuleRec;
    > TModuleRec = record
    > Succeeded : Boolean; (*Pass or failed on
    compile*)
    > Error : PChar; (*Error message if
    failed*)
    > DebugFlag : Boolean; (*Indicates there's
    debug data*)
    >
    > TargetModule : Byte; (*BASIC Stamp Module
    to compile for. 0=None, 1=BS1, 2=BS2, 3=BS2e, 4=BS2sx, 5=BS2p,
    6=BS2pe*)
    > TargetStart : Integer; (*Beginning of $STAMP
    directive target, in source*)
    > ProjectFiles : array [noparse][[/noparse]1..7] of PChar; (*Paths and names of
    related project files, if any*)
    > ProjectFilesStart : array [noparse][[/noparse]1..7] of Integer;(*Beginning of
    project file name in source*)
    >
    > Port : PChar; (*COM port to
    download to*)
    > PortStart : Integer; (*Beginning of port
    name in source*)
    >
    > SourceSize : Integer; (*Enter actual source
    code length here*)
    > ErrorStart : Integer; (*Beginning of error
    in source*)
    > ErrorLength : Integer; (*Number of bytes in
    error selection*)
    >
    > EEPROM : array [noparse][[/noparse]1..EEPROMSize] of byte; (*Tokenized data if
    compile worked*)
    > EEPROMFlags : array [noparse][[/noparse]1..EEPROMSize] of byte;(*EEPROM flags, bit
    7: 0=unused, 1=used*)
    >
    > (*bits 0..6: 0=empty, 1=undef data,
    2=def data, 3=program*)
    >
    > VarCounts : array [noparse][[/noparse]1..4] of byte; (*# of.. [noparse][[/noparse]0]=bits, [noparse][[/noparse]1]
    =nibbles, [noparse][[/noparse]2]=bytes, [noparse][[/noparse]3]=words*)
    > PacketCount : Byte; (*# of
    packets*)
    > PacketBuffer : array [noparse][[/noparse]1..2304] of byte; (*packet data*)
    > end;
    >
    > var
    > TokenizerTestForm: TTokenizerTestForm;
    > TokenizerVersion : Integer;
    >
    >
    > function Version: Integer pascal; external 'tokenizer.dll';
    > function TestRecAlignment(Rec : TModuleRec) : Boolean pascal;
    > external 'tokenizer.dll';
    > function Compile(Rec : TModuleRec;
    > Src : PChar;
    > DirectivesOnly : Boolean;
    > ParseStampDirective : Boolean) : Boolean pascal;
    > external 'tokenizer.dll';
    >
    > var
    > TestRec : TModuleRec;
    >
    > procedure TTokenizerTestForm.FormCreate(Sender: TObject);
    > var
    > SrcBuf : PChar;
    > begin
    > TokenizerVersion := Version();
    > Label1.Caption := Concat(Label1.Caption, Format('%4.2f',
    [noparse][[/noparse]TokenizerVersion/100]));
    >
    >
    > if not TestRecAlignment(TestRec) then
    > ShowMessage('TestRecAlignment failed!')
    > else
    > ShowMessage('TestRecAlignment worked!');
    >
    > SrcBuf := StrNew('''{$Stamp BS2} ''test'#$0D#$0A'debug
    HI!'#$0D#$0A'outs=65535'#0);
    > ShowMessage(SrcBuf);
    >
    > TestRec.SourceSize := StrLen(SrcBuf);
    > if not Compile(TestRec, SrcBuf, True, True) then // <---The error
    occurs here.
    > ShowMessage('Compile failed!');
    > end;
    >
    > end.
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-18 03:44
    When our new compiler is fully released we will release an updated tokenizer
    for 3rd party developers.

    -- Jon Williams
    -- Parallax

    In a message dated 4/17/2003 8:52:19 PM Central Standard Time,
    GWR@P... writes:

    > So now I've gotten it to compile a simple program, but I have now
    > discovered that it doesn't recognize the $PBasic directive! Does
    > anyone know when Parallax will be releasing a PBASIC 2.5 version?



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-18 04:06
    This is slightly off-topic, but does anyone know how to print a conductive
    material on a piece of transparency? (I'm using a charge-transfer panel to
    do inductive switches...) I thought that one might be able to use that
    laser toner stuff that you could apply metallic foil to, but maybe there's
    a better / more "professional" way of doing it.

    Suggestions? Failing that, where I can get a really thin PCB... I suppose
    the other way to do is to "draw" it on with one of those metallic pens (I
    know this comes up fairly frequently, but what's a good source of
    conductive pens?)

    Sean T. Lamont, Chief Mad Scientist |-- lamont@a...
    Zen Chemical Productions |-- http://www.zenchemical.com
    Fabricators of Unnecessary Amazement
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-18 04:33
    Are you sure you can't print the toner on a piece of transparency and then
    use some sort of plating bath to coat it with a metal film? If the toner is
    conductive you should be able to electroplate it.

    > This is slightly off-topic, but does anyone know how to print a conductive
    > material on a piece of transparency? (I'm using a charge-transfer panel to
    > do inductive switches...) I thought that one might be able to use that
    > laser toner stuff that you could apply metallic foil to, but maybe there's
    > a better / more "professional" way of doing it.
    >
    > Suggestions? Failing that, where I can get a really thin PCB... I suppose
    > the other way to do is to "draw" it on with one of those metallic pens (I
    > know this comes up fairly frequently, but what's a good source of
    > conductive pens?)
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-18 06:23
    Thanks, Jon. I'm waiting with bated breath.

    Greg Ross



    Original Message
    From: <jonwms@a...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, April 17, 2003 7:44 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Re: Has anyone used the tokenizer with Dephi?


    > When our new compiler is fully released we will release an updated
    tokenizer
    > for 3rd party developers.
    >
    > -- Jon Williams
    > -- Parallax
Sign In or Register to comment.