From: fv@nospam.tcenl.com   
      
   Robert AH Prins schreef:   
   > "Jim Leonard" wrote in message   
   > news:1135118854.510211.74340@g49g2000cwa.googlegroups.com...   
   >   
   >>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'; 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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|