设置动态链接库的字符串值... [英] Setting dynamic link library's string value...

查看:86
本文介绍了设置动态链接库的字符串值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在尝试在类库(Dll)中设置字符串值但是它的抛出异常



对象引用未设置为对象的实例。



这是我的代码

Hi friends,

I'm trying to set string value in class library(Dll) but its throwing exception

Object reference not set to an instance of an object.

This is my code

if (string.IsNullOrWhiteSpace(txtDistName.Text.Trim())== false)
                  objindcls.TxtAppl_Name = txtDistName.Text.Trim();



它进入内部如果然后抛出异常

这里,TxtAppl_Name是在类库中使用数据类型字符串定义的属性....



我用相同的方式完成了很多时间,但不知道为什么这次抛出这样的错误...

Thnx任何帮助


it's going inside if and then throws exception
here, TxtAppl_Name is property which is defined in class library with datatype string....

I've done this lots of time using same way but dont know why its throwing such error this time...
Thnx for any help

推荐答案

我们无法根据一行代码回答!

但有两种可能性:

1) Obj null

2) txtDistName null (或者它的Text属性是)

哪一个真的由您决定。

txtDistName 看起来像TextBox,所以如果它不是null,那么它的Text属性也不会(除非你在你的代码中做了一些非常愚蠢的事情)如果您在错误的位置执行此代码,则可能为null。



所以:使用调试器,在断点上设置一个断点排队并运行您的代码。触发断点时,在调试器中查看 Obj txtDistName (将鼠标依次悬停在它们上)并找出哪一个是不正确的。



然后你可以使用调试器找出你的代码在它之前变为空的位置(或者错过了应该的代码给它一个价值)。



对不起,但我们不能为你做到这一点!
We can't answer based on just one line of code!
But there are two possibilities:
1) Obj is null
2) txtDistName is null (or it's Text property is)
Which one is really up to you to find out.
txtDistName looks like a TextBox, so if it is not null, then it's Text property will not be either (unless you have done something really silly in your code and assigned null to it - unlikely) It could be null, if you are executing this code in the wrong place.

So: use the debugger, put a breakpoint on the line and run your code. When the breakpoint is fired, look at Obj and txtDistName in the debugger (by hovering the mouse over them in turn) and find out which one is incorrect.

You can then use the debugger to find out where in your code before that it becomes null (or misses out the code that should give it a value).

Sorry, but we can't do that for you!


请检查对象是谁在访问房产之前它是否为空..



检查参考类型总是好的



Please check the object whther it is null or not before accessing the properties..

Its always good to check the reference types

if (string.IsNullOrWhiteSpace(txtDistName.Text.Trim()) == false)
               if( objindcls != null)
               objindcls.TxtAppl_Name = txtDistName.Text.Trim();


这篇关于设置动态链接库的字符串值...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆