Re: How to iterate through 80-100 procedures?



Robert AH Prins schreef:
"Jim Leonard" <MobyGamer@xxxxxxxxx> wrote in message news:1135118854.510211.74340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

In building a recent Turbo Pascal 7.0 program, I've run into an odd
programming wall that I don't quite know how to get past, and am
looking for advice. Here's my situation: I'm writing a program that
needs to execute between 80 and 100 tests (all using a small snippet of
inline asm code) and I need to be able to execute each test
individually as well as execute all tests at once. Is there an easy
way to do this without trying to remember each procedure's name and
hoping that I don't forget something in a long init section, etc.?


Maybe a better way to describe what I'm looking for is to describe what
I'm NOT looking for. Each test is embedded in an object with an init
section (that sets up the test), a "do" section (that runs the test), a
"keyword" section (where it returns an 8-character description of what
test the object is), and a "report" section (that reports the test run
in numbers). So my init section looks like:


Procedure StartTests;
begin
test_foo.init;
test_bar.init;
test_baz.init;
.
.
.


and so on for nearly 100 lines. Is there any way to "loop" through all
my objects instead of having to init them all manually like this?


Likewise, I would like to run an object's method based on the output of
some other object -- is there any way to run an object based on for
example the output of it's "keyword" method instead of having to know
or remember the object's name? I guess what I'm asking is -- is there
a way to maintain an "array" of procedures or objects? If so, what
would this look like and how would I use it? I've seen other code that
defines procedure variables but I'm afraid I really don't understand
them.


Thanks to any and all advice!



In one of my programs - plain Pascal, no Objects...

type
  proc_rec = record
               key : array[1..4] of char;
               proc: procedure; {<---}
               pos : word;
               fil : string[5];
             end;

{*
Control array for 'rtf_engine'.
*}
const
proc_arr: array [0..7] of proc_rec =
((key: 'Qual'; proc: process_quality_tab; pos: 55; fil: ''),
(key: ' DT '; proc: process_dtns_tab; pos: 24; fil: ''),
(key: ' DC '; proc: process_dtns_c_tab; pos: 14; fil: ''),
(key: 'Firs'; proc: process_fila_tab; pos: 12; fil: ''),
(key: ' T='; proc: process_mima_tab; pos: 85; fil: ''),
(key: ' T='; proc: process_mima_tab; pos: 91; fil: ''),
(key: ' #R '; proc: process_inex_tcn; pos: 42; fil: ''),
(key: 'S<T>'; proc: process_day_tab; pos: 87; fil: ''));


procedure rtf_engine;
var _i: integer;

begin
  __eof:= false;

  repeat
    new_sect:= #218;
    reader(#218#196#196#196, 1);

    if not __eof then
      begin
        next;

        _i:= -1;

        repeat
          inc(_i);

          move(_line[proc_arr[_i].pos], this, 4);

          if longint(this) = longint(proc_arr[_i].key) then
            begin
              proc_arr[_i].proc; {<-- This is the call}
              _i:= -1;
            end;
        until (_i = -1) or
              (_i = pred((sizeof(proc_arr) div sizeof(proc_arr[0]))));

        if _i <> -1 then
          writer(_line);
      end;
  until __eof;
end; {rtf_engine}


IIRC there is a small example program in the TP package that demonstrates the use of these procedural types, called procvar.pas


--
Femme
.



Relevant Pages

  • I want increase the space of home folder - plz help me regarding this
    ... I want to increase the HDD space for /home ... No more tasks for init ... > try to execute ash instead of init ... Going to execute /sbin/init ...
    (RedHat)
  • some UMSDOS issues
    ... Using the Slackware lowmem kernel, as well as my own 2.4.24 kernel; ... will load init okay, but anything init tries to run (such as ... INIT: cannot execute "/sbin/agetty" ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Query in adding application in Linux
    ... For 'test' to execute it must have the executable flag set, in this case for the root user, ... init is a program on the embeded system that starts all other processes. ... As init itself is an executable, you will have to find init,c on your embedded system, ... int start_telnetd ...
    (comp.os.linux.development.apps)
  • Re: How do I show an error happening in Application_Start ?
    ... Let's start with just the Init event questions: ... >(already this is *NOT* a very good thing, because I might want to execute ... What happens in the case where I start the app normally, ...
    (microsoft.public.dotnet.framework.aspnet)