forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Display problem with "%ls" and "%rs"

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Thu Jan 22, 2009 5:26 pm    Post subject: Display problem with "%ls" and "%rs" Reply with quote

Hi,

I'm using a licensed version of FTN95 (4.6.0.0) with Windows 2000 Professional (office PC) and Windows XP (home laptop), respectively.
In both environments, the following problem occurs.

I'm using a couple of "%ls" commands in several places to display some data for the user to choose from. However, in many of these drop down boxes, there appears only a bunch of random data strings, probably taken from some abitrary memory locations.
I should add that I'm in the middle of a major program change, so the program hasn't been compiled in a long time, and that some of these boxes worked fine before the change, which opens up a variety of possible causes for the problem.

In the current version, I have found that for very simple cases, such as using static data fields and hard-coded size descriptors, it works fine. However, as soon as I try to make anything about it dynamic, even if it's only a variable giving the size of the displayed array, the mentioned problem appears.

I'm having problems putting my finger on just what exactly I did differently when it worked. But I will continue to look for differences in working and non-working versions of the situation.

My question now is if anyone has experienced something like that before and can point me in a direction that I might have missed.

---
On another note, I'm experiencing a similar problem with the "%rs" command: Even though the string is initialized, the "text field" is actually just a see-through area that displays whatever was visible at that location in the most recently opened other view (such as the desktop or browser).
This problem I have just experience today on the mentioned work PC (with Win 2000 Pro), but I assume it's going to be the same on my home laptop.

I just mention this here because these two problems seem similar enough that they might be connected.

Thank you.
Rainer
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Jan 23, 2009 10:05 am    Post subject: Reply with quote

This sounds like a programming error.
If you post some code for me to look at please make it short and embed it in a complete working program.
Back to top
View user's profile Send private message AIM Address
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Fri Jan 23, 2009 4:11 pm    Post subject: Reply with quote

Hello again.

Here is a short sample program that displays a similar behaviour to what I described yesterday. The only difference is that one of the displayed strings includes the actual string ("DEF") and then adds some apparently random symbols. However, the rest is still totally random or empty.

If I replace the line including "%ls" with either of the currently outcommented lines, the drop down box works normally.

Code:

winapp  5000000,5000000

PROGRAM TEST
  use clrwin

  character (len = 5) :: spe(5)
  integer :: nr_spe, sel, in

  spe = (/ "ABC  ", "DEF  ", "GHI  ", "JKL  ", "MNO  " /)
  nr_spe = 5
  sel = 1

  in=winio@('%`ls&', spe(1:nr_spe), nr_spe, sel)
!  in=winio@('%`ls&', spe, 5, sel)
!  in=winio@('%`ls&', spe(1:5), 5, sel)
  in=winio@('')

END PROGRAM TEST
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Fri Jan 23, 2009 6:57 pm    Post subject: Reply with quote

The problem is that the text string array that is passed, only needs to have the address of the first element you want to use, and the variable nr_spe specifies how many elements of this array to use.

If you had passed spe(1) and nr_spe=5 then it would also work. You could also pass spe(2) and nr_spe=4, and this would display the list from the second element.

I tried passing your text string to a subroutine, but the routine knew the length of the elements, so perhaps the %ls routine is programmed in another language which is not as clever as Fortran.

Regards

Ian
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Sat Jan 24, 2009 4:04 pm    Post subject: Reply with quote

winio@ is written in C. I am not sure if what you experience constitutes a bug or is simply a limitation when passing Fortran arrays.

If you need to use the form spe(1:nr_spe) then you will also need to store it as temporary array before using it.

Code:
winapp
PROGRAM TEST
  character (len = 5) :: spe(5)
  integer :: nr_spe, sel, in, winio@
  character (len = 5),allocatable :: tmp(:)
  spe = (/ "ABC  ", "DEF  ", "GHI  ", "JKL  ", "MNO  " /)
  nr_spe = 5
  sel = 1
  allocate(tmp(1:nr_spe))
  tmp = spe(1:nr_spe)
  in=winio@('%`ls', tmp, nr_spe, sel)
END PROGRAM TEST
Back to top
View user's profile Send private message AIM Address
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Sat Jan 24, 2009 4:59 pm    Post subject: Reply with quote

Paul,

I don't think it is a problem, because one would never want to pass the array in the form "spe(1:nr_spe)" because this is identical to passing either "spe" or "spe(1)" and "nr_spe" as the two required parameters. This is the documented requirements of the Clearwin+ function.

If "nr_spe" was not a parameter, then maybe it would be an OK method.

Regards

Ian
Back to top
View user's profile Send private message Send e-mail
Rainer



Joined: 13 Mar 2006
Posts: 43

PostPosted: Sat Jan 24, 2009 7:52 pm    Post subject: Reply with quote

Hi there.
Thanks everyone. It's working now.
I guess I never really understood where Fortran differentiates between variable and address, so maybe that's the reason I didn't think of this.
The examples for %ls and other commands in the book or online reference use the complete string array, so I always thought it was an array being passed. Since in my actual application I placed the strings I wanted to use inside a new data type, I had to specifically insert a ":" at some point anyway, so that it looked something like "datatype( : )%name". When the ":" alone didn't work, I guess I was stuck with the explicit array idea. But now I know what to watch out for.

Still, when I used a local array where I just copied the data into, like
"localstrings = datatype(1:N)%name"
it didn't work.
But now I'm just using a global string array to store the names and it works.

So, thanks again.
Rainer
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group