EXIT a paragraph from a called paragraph - cobol

i am trying to exit a paragraph from a called paragraph
This is my code:
PROCEDURE DIVISION.
display "PGM LEAV9POW: DEBUT"
display "PGM LEAV9POW: DEBUT PROCEDURE NOM_PROC1"
PERFORM NOM_PROC1 THRU E--NOM_PROC1
display "PGM LEAV9POW: FIN PROCEDURE NOM_PROC1"
display "PGM LEAV9POW: FIN"
GOBACK.
NOM_PROC1.
PERFORM LABEL1 THRU E--LABEL1
CONTINUE.
E--NOM_PROC1.
EXIT.
LABEL1 SECTION.
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 4
display "PGM LEAV9POW: I AM LABEL1 CALL N°" I
PERFORM LABEL2 THRU E--LABEL2
PERFORM LABEL3 THRU E--LABEL3
END-PERFORM
CONTINUE.
E--LABEL1.
EXIT.
LABEL2.
display "PGM LEAV9POW: I AM LABEL2"
display "PGM LEAV9POW: I WILL LEAVE LABEL1"
EXIT SECTION
CONTINUE.
E--LABEL2.
EXIT.
LABEL3.
display "PGM LEAV9POW: I AM LABEL3"
CONTINUE.
E--LABEL3.
EXIT.
I have as a result:
PGM LEAV9POW: DEBUT
PGM LEAV9POW: DEBUT PROCEDURE NOM_PROC1
PGM LEAV9POW: I AM LABEL1 CALL N°01
PGM LEAV9POW: I AM LABEL2
PGM LEAV9POW: I WILL LEAVE LABEL1
I think i should have:
PGM LEAV9POW: DEBUT
PGM LEAV9POW: DEBUT PROCEDURE NOM_PROC1
PGM LEAV9POW: I AM LABEL1 CALL N°01
PGM LEAV9POW: I AM LABEL2
PGM LEAV9POW: I WILL LEAVE LABEL1
PGM LEAV9POW: FIN PROCEDURE NOM_PROC1
PGM LEAV9POW: FIN
Thanks in advance for yours helps and advices.
This is the code that worked for me:
PROC1.
PERFORM LABEL1 THRU E--LABEL1
PERFORM LABEL4 THRU E--LABEL4
CONTINUE.
E--PROC1.
EXIT.
LABEL1 SECTION.
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 2
display "PGM LEAV9POW: I AM LABEL1 CALL N " I
PERFORM LABEL2 THRU E--LABEL2
PERFORM LABEL3 THRU E--LABEL3
END-PERFORM
CONTINUE.
E--LABEL1 SECTION.
EXIT SECTION.
LABEL2.
display "PGM LEAV9POW: I AM LABEL2"
display "PGM LEAV9POW: I WILL LEAVE LABEL1"
IF J = 1 THEN
EXIT SECTION
END-IF
CONTINUE.
E--LABEL2.
EXIT.
LABEL3.
display "PGM LEAV9POW: I AM LABEL3"
CONTINUE.
E--LABEL3.
EXIT.
LABEL4.
display "PGM LEAV9POW: I AM LABEL4"
CONTINUE.
E--LABEL4.
EXIT.

Easiest fix, from the top level original listing. Drop the THRU when performing the LABEL1 SECTION
NOM_PROC1.
PERFORM LABEL1 THRU E--LABEL1
to
NOM_PROC1.
PERFORM LABEL1
and compile the code with -cb_conf=perform-osvs:yes
We'll look into some of the deeper issues, but the code is bumping into an old System/370 compatibility issue (the default) in regards to section ends not being detected when jumping into the last paragraph, versus so-called OSVS mode where the section jumps have special testing regarding the last paragraph. (That is somewhat of an oversimplification of what is going on here).
THRU with SECTION is something that we'll need to look into. Either a warning, or a code flow correction in GnuCOBOL to make this work as expected.
prompt$ cobc -xjd secex2.cob -cb_conf=perform-osvs:yes
PGM LEAV9POW: DEBUT
PGM LEAV9POW: DEBUT PROCEDURE NOM_PROC1
PGM LEAV9POW: I AM LABEL1 CALL N°01
PGM LEAV9POW: I AM LABEL2
PGM LEAV9POW: I WILL LEAVE LABEL1
PGM LEAV9POW: FIN PROCEDURE NOM_PROC1
PGM LEAV9POW: FIN
That's with the THRU E--LABEL1 phrase commented out from the original listing and GnuCOBOL 2.0. GnuCOBOL 1.1 should work the same way given a .conf setting with perfrom-osvs: yes once the section THRU is removed.

Admittedly, I haven't written any COBOL in more than 30 years...
EXIT SECTION does precisely what it sounds like it does; it exits the entire section completely. In your case, this returns you to NOM_PROC1 which in turn returns you to the main procedure. You could try:
EXIT PARAGRAPH

Related

TStringGrid cannot display very long (6K) strings

I want to load some text in a TStringGrid. The strings are short except for a column where the string is over 100K. It seems that TStringGrid cannot handle this. The text does not appear in the cell until I double click the cell to edit it. But even then the behavior is erratic.
To reproduce: put a grid on the form, set goEdit= true. Run the application and double click a cell. Paste some text (should not contain enters) and press Enter to end the editing. The text disappear.
In the text I made, the limit is about 6208 ASCII chars.
Any quick fix/workaround for this?
The text is painted with ExtTextOut. That is known to fail for very long strings. For instance: ExtTextOut fails with very long strings unless lower font quality specified. From what I can tell, it is tricky to work out exactly what length of string causes failure.
I suggest that if you need to support such long strings then you draw them yourself by implementing an OnDrawCell event handler. Don't draw the entire string, because after all the user won't be able to see anything outside the cell's rectangle. That way you will be able to avoid the problem of sending ExtTextOut a string that is too long for it to handle.
you need to use Word break. of course without Word break nothing will be displayed. and of couse your text must contain spaces.
const
N = 16000;
var
R: TRect;
s: String;
i: Integer;
begin
R := ClientRect;
SetLength(s, N);
for i := 1 to N do
if Random(10) = 0 then
s[i] := ' '
else
s[i] := Char(65 + Random(26));
Canvas.Font.Color := clBlack;
Canvas.TextRect(R, s, [tfCenter, tfVerticalCenter, tfWordBreak]);
end;

TMemo max width

Is there any way to make TMemo display text longer than 1024 into 1 line?
Take a look this simple code:
procedure TForm1.Button2Click(Sender: TObject);
var
s: string;
i: integer;
begin
s := '';
for i := 0 to 10000 do
s := s + 'a';
Memo1.Clear;
Memo1.Lines.Add(s);
end;
The long text "s" will be displayed in multiple lines. The Memo1 will automatically wrap the text after 1024 characters.
A TMemo is a wrapper for a native multi line edit control and is subject to the limitations it has. From INFO: Size Limits for a Multiline Edit Control:
A multiline edit control is also subject to the following limitations:
The maximum number of characters in a single line is 1024.
The maximum width of a line is 30,000 pixels.
The maximum number of lines is approximately 16,350.

Print fields alignment misaligned on report

I have the following PrintValue code that prints a line to the report (tbasedxreportlink). It prints two fields on one line in the header, the caption and m. The problem is that m is never aligned straight for multiple lines. It always prints all over the place.
How do I get it to align to the right or even print decimal aligned.
Printed Data
Caption One 4,685.33
Caption 2 4.99
Caption three 74,586.88
Caption 4 58.66
Code
procedure PrintValue(Caption, Value: string);
var
m: string;
s: string;
begin
m := FormatFloat(',0.00 ;(,0.00);0.00 ', StrToFloat(Value));
s := Format('%-24s %15s', [Caption, m]);
AReportLink.PrinterPage.PageHeader.LeftTitle.Add(s);
end;
The font used on the report is Segoe UI if it matters.
Thanks
The simplest way is using monospace (fixed-width) font, for example, Courier New or Lucida Console
I found no easy way to format the strings to get the desired effect. The main reason for that is the simplicity of using the LeftTitle, CenterTitle or RightTitle 'boxes' - they only allow simple string text to be inserted. Nothing fancy allowed not to mention the True Type Font issue.
In order to solve the problem I added a tPanel to the screen and dropped the all screen fields I needed to show up on the grid print to it. I added a tdxCustomContainerReportLink to link to that panel. I then used a tdxCompositionReportLink to print both the grid and the tdxCustomContainerReportLink (panel) as individual items when the print button was pressed by overwriting the current link code:
procedure TFrmViewAcct.dxBarBtnPrintClick(Sender: TObject);
begin
dxCmpntPrtrDetail.CurrentLink := dxCmpntPrtrDetailLink2;
inherited;
end;
Thus it prints the grid info then prints what ever is on the panel. Problem solved and you can see how this solution can be flexible.
Yes I could have easily changed to a True Type font but that is an ugly workaround as far as I am concerned especially where standardized fonts need to be observed.

Is it possible to make a TListView search by the caption of a different column in Delphi?

When you set the Caption of a TListItem it seems to always set the Text for the first column in the row. When you start typing in the ListView it will search & select the closest match based on the caption of the first column.
I have a situation where I need the caption of the first row to be empty, but still need the search functionality to work as normal (in this case the data I would be searching for may be in the 2nd/3rd column).
Is this possible without using any 3rd party controls?
Depending on why you want the caption/ first column to be blank, you could move the text you want to search for into the caption, and then have a blank sub-item. Then swap the column order in code like so
//Move the 1st sub-item left one column
ListView1.Columns[1].Index := 0;
This would look almost the same, with the exception that if you don't have RowSelect set to true the highlighted caption will be in the wrong column. This would allow you to search as required and use the FindCaption method in code.
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
li : TListItem;
begin
//Add data to the list view for demo
for I := 0 to 10 do
begin
li := ListView1.Items.Add;
li.Caption := intToStr(Random(10000));
li.SubItems.Add('');
li.SubItems.Add('Col2');
//addimages so you can see which column is which
li.SubItemImages[0] := 0;
li.ImageIndex := -1;
end;
//move column 2 left one, this is the important bit
ListView1.Columns[1].Index := 0;
end;
alt text http://img265.imageshack.us/img265/3489/captureqg.jpg
If it's bound to a dataset, then you can do your own search and then move the dataset cursor to the row that you want. Just off the top of my head, because I just did one of those.
Update: Use the OnCompare handler, and do your own comparision on whatever criteria you want. i.e. you get to decide whether item1 < item2 or not.
Here's a nice writeup:
http://www.latiumsoftware.com/en/delphi/00011.php

How do I make a memo column on a DX grid show partial words?

I've got a TdxDBGrid that's displaying some information retrieved from a database query. One of the columns is a Memo column, (TdxDbGridMemoColumn,) which is necessary because the data in the field it's bound to comes out of the database as type TEXT, not CHAR or VARCHAR.
Problem is, the memo column likes to display whole words, and if it can't display a whole word, it doesn't display any part of it. The normal grid columns show everything they can up to the right border and cut off the display there, but the memo column doesn't, and that's bound to confuse end-users. Is there any way I can get the memo column to display partial words?
You could owner-draw the column. Then you can make the text look however you want. Call DrawText and use the dt_End_Ellipsis flag to draw an ellipsis on the end of long text, or else just let the long text be clipped to the drawing area.
in the onGetText event of the column, you can modify the displayed text to accommodate the available size:
// the TTextFormats flags are defined in Graphics, add it to your uses clause
procedure TMyForm.gridMyColGetText(Sender: TObject; ANode: TdxTreeListNode;
var AText: string);
var
R: TRect;
begin
// Calculate actual displayable text (with ellipsis) depending on cell size
R := (Sender as TdxDBGridColumn).TreeList.CellRect(ANode, (Sender as TdxDBGridColumn).ColIndex); // get the cell rectangle
Windows.InflateRect(R, -2, 0); // shrink a bit for grid lines
grid.Canvas.TextRect(R, AText, [tfModifyString, tfEndEllipsis]); // shorten the text ...
end;

Resources